I have 2 Classes in ssservice.h
:
class ssverbindungsdaten {
public:
ssverbindungsdaten();
~ssverbindungsdaten();
int id;
string test;
};
class softswitch {
public:
softswitch();
~softswitch();
list<ssverbindungsdaten> holeAlleRohdaten();
};
My ssservice.ccp
:
list<ssverbindungsdaten> softswitch::holeAlleRohdaten() {
//ssverbindungsdaten * ssv = new ssverbindungsdaten;
list<ssverbindungsdaten> *listTmp = new list<ssverbindungsdaten>;
return *listTmp;
}
And my main.cpp:
int main() {
std::cout << "Starte ...";
softswitch *ss = new softswitch;
list<ssverbindungsdaten> *liSSVVerbinngsdaten = new list<ssverbindungsdaten>();
liSSVVerbinngsdaten = ss->holeAlleRohdaten();
}
But there is an error in main.cpp
:
cannot convert ‘std::__cxx11::list<ssverbindungsdaten>’
to ‘std::__cxx11::list<ssverbindungsdaten>*’
in assignment
liSSVVerbinngsdaten = ss->holeAlleRohdaten();
The list holeAlleRohdaten
should be a lsit, containing all Classes ssverbindungsdaten
.
That I can later loop trough the liSSVVerbinngsdaten
in main.cpp
, and get all Classes ssverbindungsdaten
with the values (int id, string test)
.
Why can't I just assing the List liSSVVerbinngsdaten
to ss->holeAlleRohdaten
?
list<ssverbindungsdaten> *listTmp = new list<ssverbindungsdaten>;
The "new" keyword in c++ actually allocates a new pointer, so you are manually allocating a pointer to a list of ssverbindungsdaten objects. If you want to create a default instance of the class or list just use
list<ssverbindungen> listTmp;
Edit: Also stop coding in german and uppercase your class names