I
Intiha
Hi,
I was trying to use a member class (B in the example) to update
(basically tell me when something is done- asynchronously!) something
in base class (A in this case).
I was hoping to be able to pass A's "this" pointer so that i can update
values for a specific object via a member object. The following doesnt
work. Is there a better solution on how to do this?
class A;
class B{
B();
~B();
A* ptr;
void set(A* callbackptr){ptr=callbackptr;};
void call(int i){ptr->callback(i);};
};
class A{
public:
A();
~A();
B temp;
void callback(int i){ cout<<"callback with value "<<i<<endl;};
void setCallback(){temp.set(this);};
};
void main(int){
A test;
test.setCallback();
test.temp.call(5);
}
I was trying to use a member class (B in the example) to update
(basically tell me when something is done- asynchronously!) something
in base class (A in this case).
I was hoping to be able to pass A's "this" pointer so that i can update
values for a specific object via a member object. The following doesnt
work. Is there a better solution on how to do this?
class A;
class B{
B();
~B();
A* ptr;
void set(A* callbackptr){ptr=callbackptr;};
void call(int i){ptr->callback(i);};
};
class A{
public:
A();
~A();
B temp;
void callback(int i){ cout<<"callback with value "<<i<<endl;};
void setCallback(){temp.set(this);};
};
void main(int){
A test;
test.setCallback();
test.temp.call(5);
}