|
-
Dec 18th, 2002, 12:51 PM
#1
Thread Starter
Member
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.
-
Dec 18th, 2002, 01:40 PM
#2
Frenzied Member
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.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Dec 18th, 2002, 01:44 PM
#3
Thread Starter
Member
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.
-
Dec 18th, 2002, 02:15 PM
#4
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 18th, 2002, 02:18 PM
#5
Frenzied Member
Yeah keda really good to see you again my friend, glad to be back in bussiness
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Dec 18th, 2002, 02:22 PM
#6
Thread Starter
Member
Thread? I didnt start any threads? Can you show me using the Class1, Class2 illustration how you would do that?
Thx
-
Dec 18th, 2002, 05:07 PM
#7
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) {};
};
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|