Edit: Thanks, amazing help, as always :)
I can't find the solution to this, I have an unique_ptr to a base class, that has the data of a derived class, and I want to set it's type to the derived class so I can access the derived members. See this code:
#include <memory>
#include <iostream>
class Base
{
public:
int v1 = 0xAAAAAAAA;
};
class Derived : public Base
{
public:
int v2 = 0xBBBBBBBB;
};
int main()
{
std::unique_ptr<Base> b1(new Derived); //How to access b1->v2 ?
std::unique_ptr<Base> b2(new Base);
std::getchar();
return 0;
}
The type of b1 is Base but it's data contains the data of Derived. See:
Is it hard to get ? I thought about manipulating memory bytes, like saying [b1+4] (pseudo thoughts) and accessing it, but I think about complicated objects, because I'm doing an entity system for a game, I can't do this :(
Thanks !
(Derived*)b1->v2
but it doesn't seems to work, if this is what you mean – Phineas