Wednesday, 7 August 2013

Can I call a function of other unrelated class

Can I call a function of other unrelated class

I am not sure if it is allowed but I want to give it a try. I have 2
classes as below which are unrelated and I want to call the function
b_Method() of class B in Class A and I am interested only what boolean
value it returns.
class A
{
Public:
bool a_Method()
{
B *obj = new B();
bool varBool= obj->b_Method();
return varbool;
}
}
class B
{
public:
bool b_Method()
{
"does something"
return varBool;
}
}
I tried to call b_Method() in class A as other option would be exactly
replicate all the code of b_Method() in a_Method(), but I got following
compiler errors.
: error C2065:'A' : undeclared identifier
: error C2065: 'obj' : undeclared identifier
: error C2061: syntax error : identifier 'A'
: error C2228: left of '->b_Method' must have class/struct/union
type is ''unknown-type''

No comments:

Post a Comment