I'm trying to pass a temporary object to another object constructor for the second object to take ownership of the generated object. My code is something like this
class A {
};
class B {
A a;
public:
B(A && _a) : a(_a) {}
void test(){ }
};
int main(int argc, const char *argv[])
{
B b(A());
b.test();
return 0;
}
but I'm getting this error that I'm not able to understand
$ g++ -std=c++0x main.cpp
main.cpp: In function 'int main(int, const char**)':
main.cpp:15:7: error: request for member 'test' in 'b', which is of non-class type 'B(A (*)())'
Perhaps it is just a silly syntax error, but in case it is not, how would you defined such constructor for taking ownership of some created resource?
Thanks