This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: error: no matching function for call to `Anton::Anton(Anton)`
- From: "e.karge" <e dot karge at struction dot de>
- To: "Nathan Sidwell" <nathan at codesourcery dot com>
- Cc: "Eljay Love-Jensen" <eljay at adobe dot com>,e dot karge at struction dot de, gcc-help at gcc dot gnu dot org
- Date: Thu, 9 Oct 2003 16:42:42 +0200 (CEST)
- Subject: Re: error: no matching function for call to `Anton::Anton(Anton)`
- References: <5.2.1.1.0.20031008132129.0183dc80@iplan-mn.corp.adobe.com> <3F851C97.4040900@codesourcery.com>
- Reply-to: e dot karge at struction dot de
> Eljay Love-Jensen wrote:
>> Hi Eric,
>>
>> You should put a copy constructor in your Anton class.
>>
>> "Anton(Anton& a)" isn't a copy constructor. You need an "Anton(Anton
>> const& a)".
> Anton (Anton &), _is_ a copy constructor, it just isn't a const copy
> constructor.
> [12/1]/10
>
> You'll be able to copy non-const objects, but not copy const ones.
Sorry... maybe the example was somewhat too simple. An example, which is
closer to what I need is the following (in "reality", f() is the
constructor of another class, but the one below does not work either):
class A
{
public:
A( const A& ){}
A( A& ){}
A( int ){}
A& ref(){return *this;}
};
int f( A& ){ return 3; }
int main (int, char **)
{
return f( A( 3 ) ); // error: could not convert `A(3)' to `A&'
return f( A( 3 ).ref() ); // works
}
i wonder why it is not possible to convert to A& outside of the temporary
object but inside.
regards,
Eric.