ISO C++ forbids declaration of 'list' with no type. ?????
-
Hallo,
ich hab mir zwei klassen gemacht welche eine Musiksammlung realisieren sollen.
Beim compilieren bekomme ich in der zeilelist<CLied> m_musiksammlung; // erzeugt eine leere Liste des Typs CLiedin der klasse CMusiksammlunn folgende Fehldermeldung: ISO C++ forbids declaration of 'list' with no type.
Weiß jemand was ich da falsch mache?
LG
using namespace std; class CLied { bool found; string m_type; string m_titel; string m_interpret; string m_info; public: CLied () : m_type(""), m_titel(""), m_interpret(""), m_info("") { } CLied (string type, string titel, string interpret, string info) : m_type(type), m_titel(titel), m_interpret(interpret), m_info(info) { } /* Kopier-Konstruktor */ CLied (CLied& lied) : m_type(lied.m_type), m_titel(lied.m_titel), m_interpret(lied.m_interpret), m_info(lied.m_info) { } string getLied () { return(m_type+", "+m_titel+", "+m_interpret+", "+m_info); } bool getFound () { return (found); } void resetFound() { found = TRUE; } bool isFoundInType (string type) { if ( m_type.find(type,0) == string::npos ) { found = FALSE; return (found); } else { return (found); } } bool isFoundInTitel (string titel) { if ( m_titel.find(titel,0) == string::npos ) { found = FALSE; return (found); } else { return (found); } } bool isFoundInInterpret (string interpret) { if ( m_interpret.find(interpret,0) == string::npos ) { found = FALSE; return (found); } else { return (found); } } }; class CMuskisammlung { list<CLied> m_musiksammlung; // erzeugt eine leere Liste des Typs CLied };
-
OK sorry ich könnt mich in den Hintern beißen.
Ich hab einfach nur die zeile
#include <list>vergessen.
LG
-
BTW: Mach aus:
CLied (string type, string titel, string interpret, string info) : m_type(type), m_titel(titel), m_interpret(interpret), m_info(info) { } /* Kopier-Konstruktor */ CLied (CLied& lied) : m_type(lied.m_type), m_titel(lied.m_titel), m_interpret(lied.m_interpret), m_info(lied.m_info) { }besser:
CLied (const string& typ, const string& titel, const string& interpret, const string& info) ... // Sowie CLied (const CLied& lied) ...Und mische nicht dauernd englisch und deutsch sondern einige dich auf eine Sprache.
MfG SideWinder
-
Ok danke für die Anregungen.
Allerdings stehe ich leider vor meinem nächsten Problem:
class CMusiksammlung { list<CLied> m_musiksammlung; // erzeugt eine leere Liste des Typs CLied list<CLied>::iterator m_itor_musiksammlung; public: CMusiksammlung () { m_itor_musiksammlung = m_musiksammlung.begin(); // Iterator an den Beginn der Liste } ~CMusiksammlung () { m_musiksammlung.clear(); // Inhalt der Liste löschen, Speicherplatz freigeben } void addLiedToMusiksammlung (string type, string titel, string interpret, string info) { CLied temp_lied (type, titel, interpret, info); cout << temp_lied.getLied() << endl << endl; m_musiksammlung.push_back( temp_lied ); } };Wenn ich die Funktion "addLiedToMusiksammlung" nun aus dem main mit
CMusiksammlung meine_musiksammlung; meine_musiksammlung.addLiedToMusiksammlung("Pop", "Rocket Man", "Elton John", "asdf");aufrufe, dann kommt eine ganz liste von compiler fehlern. bei der Zeile
m_musiksammlung.push_back( temp_lied );Bin leider neu auf dem Gebiet der Objektorientieren Programmierung. Bin also für jede Hilfe dankbar.
LG
-
Hallo
Es wäre natürlich sehr hilfreich die Fehlermeldungen zu posten

Als einzigstes Problem sehe ich den Kopierkonstruktor von CLied, den die Referenz muß als const übergeben werden, sonst kommt die list-interne Verwaltung nicht damit zurecht wenn Kopieen erzeugt werden müßen./* Kopier-Konstruktor */ CLied (const CLied& lied)Siehe auch Const Correctness
bis bald
akari
-
super danke. hat wunderbar funktioniert
hab mich leider bist jetzt immer gegen const gewehrt weil ich es für überflüssig gehalten habe. danke du hast mich vom gegenteil überzeugt.
LG
-
#include <iostream> class Song { public: Song() : m_type(""), m_title(""), m_interpret(""), m_info("") { } Song(const std::string& type, const std::string& title, const std::string& interpret, const std::string& info) : m_type(type), m_title(title), m_interpret(interpret), m_info(info) { } Song(const Song& song) : m_type(song.m_type), m_title(song.m_title), m_interpret(song.m_interpret), m_info(song.m_info) { } public: std::string get_formated() const { return std::string(m_type + ", " + m_title + ", " + m_interpret + ", " + m_info); } bool is_type_in(const std::string& type) { return (m_type.find(type) != std::string::npos); } bool is_titel_in(const std::string& title) { return (m_title.find(title) != std::string::npos); } bool is_interpret_in(const std::string& interpret) { return (m_interpret.find(interpret) != std::string::npos); } private: std::string m_type; std::string m_title; std::string m_interpret; std::string m_info; }; #include <vector> class MusicCollection { public: MusicCollection() { } ~MusicCollection() { m_items.clear(); // Muss nicht! } void add_song(const std::string& type, const std::string& title, const std::string& interpret, const std::string& info) { m_items.push_back(Song(type, title, interpret, info)); } void add_song(const Song& song) { m_items.push_back(song); std::cout << song.get_formated() << std::endl; } Song* get_song(size_t id) { return (m_items.size() > id ? &m_items[id] : NULL); } private: std::vector<Song> m_items; }; #include <iostream> int main() { MusicCollection test; test.add_song("Techno", "Everytime We Touch", "Cascada", "Some information!"); Song song("Rock", "For You [Original Radio Edit]", "Disco Boys", "Covered version!"); test.add_song(song); Song* pSong = test.get_song(0); if (pSong != NULL) std::cout << pSong->get_formated() << std::endl; }... mach das mal so ^^ ist ein wenig logischer ... vor allem das mit m_found als Membervariable von CLied war nicht so sinnvoll ...
-
danke danke werd das mit der m_found nochmal überdenken. so ganz gefallen hat mir die lösung eh nicht aber das hatte für die aufgabe die es erfüllen sollte durchaus sinn gemacht. naja mal sehen vielleich fällt mir noch was anderes ein.
vielen dank jedenfalls,
LG