Code: Select all
class A
{
public: int Foo;
public: void Init()
{
Foo = 54;
cout<<"This is class A! Foo is: "<<Foo;
}
};
class B
{
public: int Bar;
public: A* obj;
public: void Init()
{
Bar = 96;
cout<<"This is class B! Foo from A is: "<<obj->Foo;
}
};
I also tried to replace:This is class B! Foo from A is: 0
Code: Select all
public: A* obj;
public: void Init()
{
Bar = 96;
cout<<"This is class B! Foo from A is: "<<obj->Foo;
}
Code: Select all
public: A obj;
public: void Init()
{
Bar = 96;
cout<<"This is class B! Foo from A is: "<<obj.Foo;
}
It's getting me nervous!This is class B! Foo from A is: 2293672
Edie:
Never mind, i realized that creating an instance on the main and calling Init is only valid for that specific instance, and wont be valid at class B.