-
Handle to Parent Class
Is there an easy way to get a handle to a parent class?
class Class1{
int m_y;
int m_x;
Class2 c2;
}
class Class2{
//I'd like to talk back to class 1 and set some variables, or call some functions
}
I tried creating a whole class pointer, but that went down in flames.
-
You could always make the members public, but it's better to encapsulate them.
Anyway, read this, since you have a long OOP way to go ;)
http://newdata.box.sk/bx/c/
good luck, and if you need concrete examples, you have to wait a day or 2 since I haven't have my VS installed yet.
-
thanks for the link, I've read that and quite a few others. Just got out of a week long MFC course. I'm certified in desktop + distributed VB, I just dont get this dammmmmed pointer between class business.
-
check your other thread, you just have to make a pointer to the other class :)
oh and LTNS jop, haven't seen you around here for ages :D
-
Yeah keda really good to see you again my friend, glad to be back in bussiness :)
-
Thread? I didnt start any threads? Can you show me using the Class1, Class2 illustration how you would do that?
Thx
-
Code:
class Class1;
class Class2{
// I'd like to talk back to class 1 and set
// some variables, or call some functions
Class1 &parent;
public:
Class2(Class1 &p) : parent(p) {};
};
class Class1{
int m_y;
int m_x;
Class2 c2;
public:
Class1() : c2(*this) {};
};