How can I use this
as a persistent pointer, so it would work outside of the current scope?
As for this example, I don't know how should I set the fx.parent
:
class Effect
{
Card* parent;
};
class Card
{
vector<Effect> effects;
void addEffect(Effect);
};
Card::addEffect(Effect fx)
{
/*
* the `this` pointer is not persistent and
* will not work outside of this scope
*/
fx.parent = this;
this->effects.push_back(fx);
}
PS: I'd be grateful for any literature about when pointers get destroyed, invalidated, etc. I could not really find anything readable. Nothing at all, actually.