Pointers
Can someone PLEASE give me the necessary code to retrieve the value of a member variable from another class! Maybe then I'll understand it.
class ClassA
{
public:
ClassA()
{
m_number = 5;
}
int m_number;
}
class ClassB
{
public:
ClassB()
{
theint = -1;
}
void GetANum(ClassA *ClassPointer);
int theint;
}
ClassB::GetANum(ClassA *ClassPointer)
{
theint = ClassPointer->m_number;
}
main()
{
ClassA MyClassA;
ClassB MyClassB;
MyClassB.GetANum(&MyClassA);
printf("%d", MyClassB.theint);
}
Obviously this is psuedocode and won't compile, but it gets the point across I think. It would print the number 5 assuming that it had the proper includes, etc.
You really should read more about pointers, they are one of the harder concepts to grasp.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement