Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > non-const refer...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 45776 of 45898
Post > Topic >>

non-const reference to temporary derived from pure virtual Base

by reppisch <spam@[EMAIL PROTECTED] > May 6, 2008 at 04:41 PM

Hi Ng,

besides that this style may be asking for trouble i'm faced with a 
unexpected gcc behaviour. Tested with gcc 3.3.3.
On M$ .Net this compiles just fine.

I'm trying to make a non-const reference to a temporary object. The 
object is derived from a pure virtual base, so the compiler can't create 
a copy of base-type.

Why does this not work with gcc?

To reproduce:
//-----------------------------------
class Base {
public:
   Base() {};
   virtual void pv()  = 0;
   virtual ~Base() {};
};

class Derived : public Base {
public:
   Derived(int i)      {};
   virtual void pv()   {};
   virtual ~Derived()  {};
};

class User {
public:
   void useBase(Base& b) {};
   void useBaseConst(const Base& b) {};
};


int main() {
   User u;
   Derived d(1);


   // Ok with non-temporary !
   u.useBase(d);

   // not ok!
   u.useBase(Derived(1));
   //*  no matching function for call to `User::useBase(Derived)'
   //*   candidates are: void User::useBase(Base&)
   // seems that the compiler refuses to make a
   // non-const reference to a temporary

   // but this is ok!
   u.useBaseConst(Derived(1));

}

Regards,

   Michael




 7 Posts in Topic:
non-const reference to temporary derived from pure virtual Base
reppisch <spam@[EMAIL   2008-05-06 16:41:40 
Re: non-const reference to temporary derived from pure virtual B
reppisch <spam@[EMAIL   2008-05-06 17:17:16 
Re: non-const reference to temporary derived from pure virtual B
Andrey Tarasevich <and  2008-05-06 10:33:20 
Re: non-const reference to temporary derived from pure virtual B
=?ISO-8859-1?Q?Marcel_M=F  2008-05-06 17:16:38 
Re: non-const reference to temporary derived from pure virtual B
=?UTF-8?B?RXJpayBXaWtzdHL  2008-05-06 16:29:20 
Re: non-const reference to temporary derived from pure virtual B
"sk_usenet" <  2008-05-06 09:40:48 
Re: non-const reference to temporary derived from pure virtual B
Andrey Tarasevich <and  2008-05-06 10:45:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 17:09:07 CDT 2008.