Returning a class object by reference inside another class

#include <stdio.h>
class A {
public:
void setX(int y) { x = y ;}
int getX() { return x; }
private:
int x;
};

class B {
public:
A& getA () {return a;}
private:
A a;
};


int main() {
B* b = new B;;
b->getA().setX(10);
printf("\n Value is %p",&(b->getA()));
b->getA().setX(5);
return 0;
}
Last edited on
Please review now and I assume there is no problem in returning object by reference in place of Singleton class ?
Topic archived. No new replies allowed.