C++ c+中的错误+;编撰

C++ c+中的错误+;编撰,c++,compilation,g++,C++,Compilation,G++,好吧,我正试图在linux服务器上编译一个学校项目,但它向我抛出了错误。我使用的编译器是g++,在我上传到这个服务器之前,这个程序在我的Mac上运行得很好。基本上,我只是不知道如何阅读这个错误消息,所以我不知道要修复什么,在哪里修复,或者你们需要看到什么代码。如果有人能告诉我在这里发布什么,你们可以进一步推断你们会很棒。。。哦,我的项目今晚11:00到期:哈哈,不管怎样,下面是我键入的命令,然后它向我吐出的消息 g++ Song.cpp Song.h test_tsuPod.cpp tsuPod

好吧,我正试图在linux服务器上编译一个学校项目,但它向我抛出了错误。我使用的编译器是g++,在我上传到这个服务器之前,这个程序在我的Mac上运行得很好。基本上,我只是不知道如何阅读这个错误消息,所以我不知道要修复什么,在哪里修复,或者你们需要看到什么代码。如果有人能告诉我在这里发布什么,你们可以进一步推断你们会很棒。。。哦,我的项目今晚11:00到期:哈哈,不管怎样,下面是我键入的命令,然后它向我吐出的消息

g++ Song.cpp Song.h test_tsuPod.cpp tsuPod.h tsuPod.cpp
现在是错误。。。。准备好胡说八道吧

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:39,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
                 from test_tsuPod.cpp:9:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/ios_base.h: In copy constructor ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/ios_base.h:790: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:47: error: within this context
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd: In copy constructor ‘std::basic_fstream<char, std::char_traits<char> >::basic_fstream(const std::basic_fstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:87: note: synthesized method ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’ first required here 
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/streambuf: In copy constructor ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/streambuf:770: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]’ is private
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:78: error: within this context
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd: In copy constructor ‘std::basic_fstream<char, std::char_traits<char> >::basic_fstream(const std::basic_fstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iosfwd:87: note: synthesized method ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’ first required here 
In file included from test_tsuPod.cpp:10:
tsuPod.h: In copy constructor ‘tsuPod::tsuPod(const tsuPod&)’:
tsuPod.h:23: note: synthesized method ‘std::basic_fstream<char, std::char_traits<char> >::basic_fstream(const std::basic_fstream<char, std::char_traits<char> >&)’ first required here 
test_tsuPod.cpp: In function ‘int main()’:
test_tsuPod.cpp:23: note: synthesized method ‘tsuPod::tsuPod(const tsuPod&)’ first required here 
在/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../include/c++/4.4.7/ios:39中包含的文件中,
从/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/ostream:40,
从/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../include/c++/4.4.7/iostream:40,
来自测试tsuPod.cpp:9:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../include/c++/4.4.7/bits/ios_base.h:在复制构造函数“std::basic_ios::basic_ios(const std::basic_ios&)”中:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/bits/ios_base.h:790:错误:“std::ios_base::ios_base(const std::ios_base&)”是私有的
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/iosfwd:47:错误:在此上下文中
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/iosfwd:在复制构造函数“std::basic_fstream::basic_fstream(const std::basic_fstream&)”中:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/iosfwd:87:注意:这里首先需要合成方法“std::basic_ios::basic_ios(const std::basic_ios&)”
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/streambuf:在复制构造函数“std::basic_filebuf::basic_filebuf(const std::basic_filebuf&)”中:
/usr/lib/gcc/x86\u 64-redhat-linux/4.4.7/../../../../../../../../../include/c++/4.4.7/streambuf:770:错误:“std::basic\u streambuf::basic\u streambuf(const std::basic\u streambuf&)[with.\u CharT=CharT,\u Traits=std::char\u Traits]”是私有的
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../include/c++/4.4.7/iosfwd:78:错误:在此上下文中
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/iosfwd:在复制构造函数“std::basic_fstream::basic_fstream(const std::basic_fstream&)”中:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../../../../../include/c++/4.4.7/iosfwd:87:注意:这里首先需要合成方法'std::basic_filebuf::basic_filebuf(const std::basic_filebuf&')
包含在test_tsuPod.cpp:10中的文件中:
h:在副本构造函数“tsuPod::tsuPod(const tsuPod&)”中:
h:23:注意:这里首先需要合成方法“std::basic\u fstream::basic\u fstream(const std::basic\u fstream&)”
test_tsuPod.cpp:在函数“int main()”中:
测试tsuPod.cpp:23:注:此处首先需要合成方法“tsuPod::tsuPod(const tsuPod&)”
如果你能救我,我将永远欠你的债!!谢谢大家!

这是来自tsuPod.h的代码

#ifndef __project5__tsuPod__
#define __project5__tsuPod__

#include <iostream>

#endif /* defined(__project5__tsuPod__) */

#include "Song.h"
#include <fstream>


using namespace std;


class tsuPod {
  private:
  int MAX_SONGS;
  int MAX_MEM;
  int num_songs;
  int memory;
  fstream file;


  public:
  int getNumSongs();
  int getMemoryUsage();
  int addSong(string, string, int);
  int deleteSong(string);
  int shuffle();
  int clearSongList();
  int showSongList();
  int sortSongList();
  int getTotalMemory();
  int getRemainingMemory();

  //constructor
  tsuPod(int, int);


};
\ifndef\uuuu项目5\uuuuu tsuPod__
#定义项目5__
#包括
#endif/*已定义(_项目5__tsuPod__)*/
#包括“Song.h”
#包括
使用名称空间std;
tsuPod类{
私人:
int MAX_歌曲;
int MAX_MEM;
int num_歌曲;
内部存储器;
流文件;
公众:
int getNumSongs();
int getMemoryUsage();
int addSong(string,string,int);
int删除歌曲(字符串);
int shuffle();
int clearSongList();
int showSongList();
int-sortSongList();
int getTotalMemory();
int getRemainingMemory();
//建造师
tsuPod(int,int);
};
你可以看到,这是我的test_tsuPod.cpp,它是这个程序的驱动程序

#include <iostream> // here is line # 9, as compiler says something about this line
#include "tsuPod.h"
#include <fstream>


using namespace std;

int main()
{
  const int MAX_SONGS = 25;
  const int MAX_MEMORY = 100;



  tsuPod TsuPodApp = tsuPod(MAX_SONGS, MAX_MEMORY);

  cout << "Total memory : " << TsuPodApp.getTotalMemory() << endl;

  TsuPodApp.addSong("Something", "artist", 80);
  TsuPodApp.addSong("2", "artist num 2", 10);

  cout << "Remaining Memory : " << TsuPodApp.getRemainingMemory() << endl;

  TsuPodApp.addSong("3", "artist num 3", 1);
  TsuPodApp.addSong("4", "artist num 4", 1);
  TsuPodApp.addSong("5", "Other artist", 10); // should trigger memory error


  TsuPodApp.showSongList();

  TsuPodApp.deleteSong("2");

  TsuPodApp.showSongList();

  cout << "Remaining Memory : " << TsuPodApp.getRemainingMemory() << endl;

  TsuPodApp.sortSongList();

  TsuPodApp.showSongList();

  TsuPodApp.clearSongList();

  TsuPodApp.showSongList();


  return 0;
}
#include//这是第#9行,因为编译器对这一行做了一些说明
#包括“tsuPod.h”
#包括
使用名称空间std;
int main()
{
const int MAX_SONGS=25;
常量int MAX_内存=100;
tsuPod TsuPodApp=tsuPod(最大歌曲数,最大内存);

cout编译器正在尝试为
tsuPod
发出隐式复制构造函数,但无法执行此操作,因为
fstream
成员不可复制。您正在尝试在
test\u tsuPod.cpp:23

复制类编译器正在尝试为
tsuPod
发出隐式复制构造函数,但它无法执行此操作因为
fstream
成员无法复制。您正试图在
test\u tsuPod.cpp:23

复制您的类。导致问题的行是:

tsuPod TsuPodApp=tsuPod(最大歌曲数,最大内存);
此行正在从临时值构造
TsuPodApp
。发生这种情况时,编译器将尝试将临时值复制到
TsuPodApp
中。但为了实现这一点,类
tsuPod
必须有一个复制构造函数。因为
std::fstream
有一个私有复制构造函数(在C++11中删除)无法复制该类,因此出现错误

解决方案是直接构建
TsuPodApp
,如下所示:

tsuPod TsuPodApp(最多歌曲,最多内存);

此处将调用的唯一构造函数是您定义的构造函数(
tsuPod(int,int)
)。

导致问题的行是:

tsuPod TsuPodApp=tsuPod(最大歌曲数,最大内存);
此行正在从临时值构造
TsuPodApp
。发生这种情况时,编译器将尝试将临时值复制到
TsuPodApp
中。但为了实现这一点,类
tsuPod
必须有一个复制构造函数。因为
std::fstream
有一个私有复制构造函数(在C++11中删除)无法复制该类,因此出现错误

解决方案是直接构建
TsuPodApp
,如下所示:

tsuPod TsuPodApp(最多歌曲,最多内存);
唯一的构造函数是t
/tmp/ccu7S45x.o: In function `tsuPod::addSong(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)':
tsuPod.cpp:(.text+0x20d): undefined reference to `Song::Song(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
tsuPod.cpp:(.text+0x28d): undefined reference to `Song::getTitle()'
tsuPod.cpp:(.text+0x2f6): undefined reference to `Song::getArtist()'
collect2: ld returned 1 exit status
#include "Song.h"



string Song::getTitle()
{
  return title;
}

string Song::getArtist()
{
  return artist;
}

int Song::getSize()
{
  return size;
}

int Song::setTitle(string some)
{
  if(some.length() == 0)
  {
    cout << "To add a song, it has to have a title."
    << endl;
    return 0;
  }

  title = some;
  return 1;
}

int Song::setArtist(string some)
{
  if(some.length() == 0)
  {
    cout << "To add a song, it has to have an artist name."
    << endl;
    return 0;
  }

  artist = some;
  return 1;
}

int Song::setSize(int some)
{
  if(some <= 0)
  {
    cout << "To add a song, it has to have minimum size of 1 mb." << endl;
    return 0;
  }

  size = some;
  return 1;
}

Song::Song(string song_title, string song_artist, int song_size)
{
  if(song_title.length() == 0 || song_artist.length() == 0)
  {
    cout << "To add a song, it has to have a name and artist name."
    << endl;
    return;
  }
  if(song_size <= 0)
  {
    cout << "To add a song, it has to have minimum size of 1 mb." << endl;
    return;
  }
  title  = song_title;
  artist = song_artist;
  size   = song_size;
}
#ifndef __project5__Song__
#define __project5__Song__

#include <iostream>
#include <string>

using namespace std;

#endif /* defined(__project5__Song__) */


class Song {
  private:
    string title;
    string artist;
    int size;
  public:
    string getTitle();
    string getArtist();
    int getSize();
    int setTitle(string);
    int setArtist(string);
    int setSize(int);

  // constructor
  Song(string, string, int);

};