By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,422 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,422 IT Pros & Developers. It's quick & easy.

How to initialize member reference with temp object and delete the temp object when the destructor is called?

P: n/a

There is something wrong with the line labeled "//error". I want D's
memeber _a point to a "C" object if it is constructed from another "D"
object. Do you have any idea how to do it? Thanks!

Best wishes,

class A{
virtual ~A(){}
virtual void fun() = 0;

class B : public A{
virtual ~B(){}
virtual void fun(){}

class C : public A{
C(A &a){}
virtual ~C(){}
virtual void fun(){}

class D{
D(A& a): _a(a) {};
D(D& d): _a(C(d._a)) {};//error
D(D& d): _a(d._a) {};//no error
A& _a;

int main(int argc, char *argv[])
B b;
D d(b);
D d1(d);

Jul 23 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.