S
stefven blonqhern
hi, i imagine we've all seen this one posted before but i can't get
any solutions to work for me.. for example:
i have two classes MyClass and Shape. MyClass creates Shapes (and
derived classes from Shape) and it also wants to pass a pointer to
itself to a member function of Shape so that it can access MyClass'
members. Pseudo code example:
class MyClass {
void MyFunction{
aShape->DoSomethingToShape(this)
}
private:
Shape* aShape;
}
/////////////
class MyClass; // forward declaration
class Shape { // is a base class
void DoSomethingToShape(MyClass* aClass) {
aClass->some_member; // ** ERROR invalid use of undefined type
'struct MyClass' **
}
I have simplified greatly (possibly too much to make proper sense).
Really i'm trying to avoid passing 10-20 references to MyClass members
because it feels a bit clumsy. I just want to pass a pointer to a
MyClass so that Shape can access what it wants.
Is there a better way?
thanks, stefven.
any solutions to work for me.. for example:
i have two classes MyClass and Shape. MyClass creates Shapes (and
derived classes from Shape) and it also wants to pass a pointer to
itself to a member function of Shape so that it can access MyClass'
members. Pseudo code example:
class MyClass {
void MyFunction{
aShape->DoSomethingToShape(this)
}
private:
Shape* aShape;
}
/////////////
class MyClass; // forward declaration
class Shape { // is a base class
void DoSomethingToShape(MyClass* aClass) {
aClass->some_member; // ** ERROR invalid use of undefined type
'struct MyClass' **
}
I have simplified greatly (possibly too much to make proper sense).
Really i'm trying to avoid passing 10-20 references to MyClass members
because it feels a bit clumsy. I just want to pass a pointer to a
MyClass so that Shape can access what it wants.
Is there a better way?
thanks, stefven.