convert unsigned int to class pointer

Hello together,

i was trying to find out, how to cast an unsigned int to a class pointer.
I´m using a stm32 under µVision4.
I read something about reinterpret casts, and that they´re not that runtime efficient.
And i don´t see (know) the reason why i´m forced to use a function wich checks the adress if it really holds the class type; plus i´m not sure if this is even supported on the µC.
if i do it the "noobish" way tmpPtr = (myClass)adressHolder; i´m told a sufficient constructor is missing. For what information do i have to search, if i want to make up such a constructor on my own.

Backround:
I have a bunch of classes and they all have "prev" and "nxt" pointer of thier own typ to form up a list. This means i have implemented a Get-, and Set- method to access the previous and next adress holder. Since i want to use descent (don´t know if it is the correct english word), i had the idea to implement the Get, Set methods with unsigend int parameter and cast them to the type i need, when required.

Greetings,
Justus

Parents
  • That looks like you're going about this whole thing bass-ackwards. C++ has way better methods for doing that, involving either templates (see STL's <dequeue> et al.) or inheritance of members and methods from shared base classes.

    Even in C, pointers aren't really all that compatible with integers. You shouldn't even think about it for C++ object pointers.

Reply
  • That looks like you're going about this whole thing bass-ackwards. C++ has way better methods for doing that, involving either templates (see STL's <dequeue> et al.) or inheritance of members and methods from shared base classes.

    Even in C, pointers aren't really all that compatible with integers. You shouldn't even think about it for C++ object pointers.

Children
More questions in this forum