A
A
Alexander Kazakevich2016-12-18 22:43:44
C++ / C#
Alexander Kazakevich, 2016-12-18 22:43:44

What happens to the pointer?

I am writing a courseworker. A very strange problem has arisen.

// Метод возвращает указатель на объект Account. Валидный, инициализированный объект, я вас уверяю на 99.99%.
Account* acc = e.getAccount();
// При попытке вызвать метод от этого указателя, указатель чудесным образом превращается... в 0xCCCCCCCC. Что простите???
User u = acc->getUser();

Screenshot 1. Before executing the method. (the 'acc' pointer refers to the area occupied by the Account object)
607bc2900f9e4a9dbe8df4a60f4d6d64.png
Screenshot 2. Direct method call.
7ed1d0bf461348c1bf25660a6cdcdd34.png
CHANTD?
If it makes things easier, or PS:
1. The friend class is used in the code.
2. There are 2 projects. The first is the DLL, where all the code is. The second one is the executable that this DLL is connected to.
3. This is my first program on the pluses, do not scold too much.
4. The Engine class creates (and stores a pointer to) the Account class, and the Account class receives (and stores) a pointer to the Engine class.
5. I won’t post the whole project, there are 20+ classes and a lot of code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
1
15432, 2016-12-18
@15432

It's possible that getUser is in a library and the studio is just having trouble debugging the lib. (e.g. no symbols). Returning a normal User object?
Well, or such an exotic option as Engine e is declared locally and self-destructed before the getUser call, deleting the Account inside itself at the same time. (try Engine through new to create)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question