Okay so I'm trying to compile a school project on a linux server, but it's throwing errors at me. The compiler I'm using is g++, & for the record this program worked fine on my Mac before i uploaded it to this server. Basically, I just don't know how to read this error message, so I don't know what to fix, where to fix, or what code you guys need to see. If someone could please tell me what to post on here so you guys can infer further you would be awesome... Oh and my project is due at 11:00 tonight :D Haha anyways, below is the command I typed and then the message it spat out at me.
g++ Song.cpp Song.h test_tsuPod.cpp tsuPod.h tsuPod.cpp
And now the error.... get ready for some gibberish
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
If you can save me, I will forever be in your debt!! Thank you!
Here is the code from 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);
};
And so you can see, here is my test_tsuPod.cpp which is the driver for this program
#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;
}
Awesome! It seems you guys fixed the cop constructor error I was having! But now when I try to compile I get this message - , which is weird because I'm positive those functions are defined. Any ideas?
/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
Alright, as requested here is Song.cpp - man this is a long post haha
#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;
}
And song.h below
#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);
};
Song.hin the list of files to compile. Assuming you have something like#include "Song.h", then the compiler will literally copy/paste the contents of the fileSong.hat that point in your source file. You don't need to tell it to compile the file again.fstream, which isn't supported even in the latest trunk version of gcc.