Saturday, 14 September 2013

Use instance of one class in another class method

Use instance of one class in another class method

I defined two classes class A and class B. They are completely
independent. Now I create c as instance of class B and d as instance of
class A. This c is called in method of A. I want to perform operations on
c using methods in B.
Sample code:
class A
{public:
functionOfA();
.....;
}
class B
{public:
functionOfB();
}
A::functionOFA()
{
c.functionOfB();
}
B::functionOfB()
{
.....
}
main()
{
A d;
B c;
d.functionOfA();
}
Compiler error: c is not declared in this scope. I tried to make it
general and short.( My original code is ~100 lines.)

No comments:

Post a Comment