weather_station.cpp: In constructor ‘Client::Client(IObservable*)’:
weather_station.cpp:65:7: error: class ‘Client’ does not have any field named ‘m_observable’
65 | : m_observable{ observable }
| ^~~~~~~~~~~~
I am not sure what the problem is, but for the information of others.
These are the errors I get on VS 2017 CE
Exception thrown: read access violation.
this->m_observable->**** was 0xDDDDDDDD. occurred
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
This is usually a result of calling a function declared with one calling convention
with a function pointer declared with a different calling convention. occurred
The value 0xdddddddd means that the memory has been freed.
This is done by the Debug version of the Microsoft CRT library. When you allocate memory it's filled with 0xcdcdcdcd, when it's freed 0xdddddddd , etc.
So the object you're trying to access has been deleted.
Thank you both. But i must confess that I don't have Windows anymore on my system installed, because I didn't need to use any of its programs, all I need I can do on my Linux distro. And there I'm coding with a simple text editor and a shell. But sometimes I miss a good debugger. Maybe a good graphical debugger would be integrated in the IDE provided by Qt.
I made several changes at my code, and one side effect (to my surprise) was, that the segfaullt error is gone.
Here the final code:
> the segfaullt error is gone.
you are just unlucky
virtual ~IObservable () {}
quite an important change, otherwise delete weather_station; will not call `WeatherStation' destructor
¿but why do you do deletenew T?
another issue ~Client() { m_observable->remove( this ); }
¿are you sure that `m_observable' is valid? (hint: it is not, you delete it on line 87)
> I got a workaround by initializing the member variable within constructor's body:
you can't put it in the initializer list because at that point `m_observable' was already constructed by the constructor of IObservable
you may let the parent manage its own variables