Help using keyword this

P

pauldepstein

Here is the problem piece of my code:

Please note that SafePointerToCats is a safe pointer (boost library)
to the Cats class, DerivedFromCats is a class that is derived from
Cats and SafePointerToDerivedFromCats is a safe pointer to
DerivedFromCats.
PointerToSomeClass is a safe pointer to SomeClass

class SomeClass
{
private: SafePointerToCats CatPointer;

public: SomeClass() {}
void setCatPointer (SafePointerToCats cat){CatPointer =
cat;}

};

//Then in some other file..

void DerivedFromCats::SomeFunction( someparameter& something,
anotherparameter& anotherthing)

{
PointerToSomeClass PointersAreCool ( new SomeClass());
PointersAreCool -> setCatPointer (this);
}

My hope was that this code would result in in CatPointer pointing at
the derived class. Instead it gave a compile error.

What is wrong here?

Thanks for your help,

Paul Epstein
 
V

Victor Bazarov

Here is the problem piece of my code:

Please note that SafePointerToCats is a safe pointer (boost library)
to the Cats class, DerivedFromCats is a class that is derived from
Cats and SafePointerToDerivedFromCats is a safe pointer to
DerivedFromCats.
PointerToSomeClass is a safe pointer to SomeClass

class SomeClass
{
private: SafePointerToCats CatPointer;

public: SomeClass() {}
void setCatPointer (SafePointerToCats cat){CatPointer =
cat;}

};

//Then in some other file..

void DerivedFromCats::SomeFunction( someparameter& something,
anotherparameter& anotherthing)

{
PointerToSomeClass PointersAreCool ( new SomeClass());
PointersAreCool -> setCatPointer (this);
}

My hope was that this code would result in in CatPointer pointing at
the derived class. Instead it gave a compile error.

What is wrong here?

No way to tell. The code you posted is incomplete. Please read and
follow the recommendations in FAQ 5.8.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,113
Latest member
Vinay KumarNevatia
Top