In C++, I want to initialize (or change) a class object using the result of another class' method. Can I use the this pointer? Is there a better way?
Dummy example:
class c_A {
public:
int a, b;
void import(void);
};
class c_B {
public:
c_A create(void);
};
void c_A::import(void) {
c_B B;
*this = B.create();
};
c_A c_B::create(void) {
c_A A;
A.a = A.b = 0;
return A;
};
Aucun commentaire:
Enregistrer un commentaire