Hi all,
I'm facing strange error. I defined a class:
class MyClass : public MyAbstractClass {
public:
MyClass() : myList(myList) {}
~MyClass() {}
void AddList(list<MyObject>& myNewList) {
myList = myNewList;
}
private:
list<MyObject>& myList;
};
And in the main I do:
// myObject is initialized here and is valid
// ...
list<MyObject> myNewList;
myNewList.push_back(myObject);
MyClass mc;
mc.AddList(myNewList);
Nice, that was a code. As you see, I create a list of objects in the main function - outside the class. Then I will be using MyClass mc, where the this list of objects is needed. I can't add the list in the constructor, because that is the request from 3d party developers. I must provide a method which will allow to set the list of objects. I've created AddList where I can assign myList reference to the new list.
The problem is constructor wants to initialize a reference, so I do fake initialization.
I don't like this, but compiler passes if I do so.
Next problem, program crashes while trying to execute AddList method. It says "Core dump".
Please, help me, poor newbie, what is wrong in my code? Why are these problems with reference as a class member. I have not have such neither python nor php. Also I do not want to use pointer to the list of objects, it is not a good time to use pointers.
Thankfully waiting for someone to clarify things.
Wish you well.