Problems with ** to dbo:: objects
Added by Norman Hampel over 1 year ago
Hi everyone,
I have a bit of a problem with the assignment of pointer-pointers. I have a main application and a dialog in seperate cpp/h files. In my main application I have a "dbo::ptr<Map> currentMap_;" (pointer to a map object) that needs to be manipulated in the dialog. at first I had passed the pointer to the dialog and worked with that. I could, of course, manipulate the object from within the dialog but the pointer to it remained unchanged. Then, luckily, I realized what a nooby mistake I had made. I don´t need to create a local pointer in the dialog that points to the same object as the dbo::ptr<Map> does; I need a * to change the object AND the dbo::ptr<Map> in the main application.
So I added a "dbo::ptr<Map> *ptrToCurrentMap_;" to the header and as long as I don´t assign it, the code compiles and runs. If I do assign it in the .cpp file (e.g. "(ptrToCurrentMap_) = currentMap_;"), the code compiles but crashes upon execution.
I´m quite the beginner when it comes to programming but I can usually handle the interface I´m currently working on. I had a heurika-moment when I realized I needed **´s (and that gives you an idea just how much of a beginner I am) but draw a blank as to why my **´s to dbo:: objects don´t work.
Using Eclipse under debian.
Any ideas/suggestions would be greatly appreciated.
Norman
Replies
RE: Problems with ** to dbo:: objects - Added by Koen Deforche over 1 year ago
Hey Norman,
You should keep the dbo::ptr<Map> currentMap_ in your main application, but pass it as a reference or pointer to your dialog:
MyDialog(dbo::ptr<Map>& map) or MyDialog(dbo::ptr<Map> *map)
In the latter form you will need to get the address of your map in your main application object using the '&' operator: ¤tMap_. Your error is to dereference a pointer which is not pointing to any storage.
Regards,
koen
RE: Problems with ** to dbo:: objects - Added by Norman Hampel over 1 year ago
Blind me, why, yes of course! That was the bloody problem. Bummer, it always seems so obvious in retrospect, doesn't it?
Kinda reminds me of Frank N. Furter's "What a fool I've been, the answer was there all the time." speech before he brings Rocky to life. Thanks ever so much, Koen, you made my day!
The loyal Wt user,
Norman