Thread View: borland.public.cppbuilder.upgrade
3 messages
3 total messages
Started by Roland
Wed, 10 Oct 2007 07:48
BCB6 to BDS2006 problems with operators
Author: Roland
Date: Wed, 10 Oct 2007 07:48
Date: Wed, 10 Oct 2007 07:48
36 lines
1758 bytes
1758 bytes
In BCB6 I could overload the = operator like:
TMyClass& __fastcall operator=(TMyClass &p);
TMyClass& __fastcall TMyClass::operator=(TMyClass &p)
{
for(int i = 0; i < 4; i++) {
FEnabled[i] = p.Enabled[i];
FPosition[i] = p.Position[i];
}
FMode = p.Mode;
FDivider = p.Divider;
return this;
}
Now in BDS2006 I get an error msg like:
[C++ Error] xutility(1645): E2285 No match found for
'TMyClass::operator =(const TMyClass)'
the IDE points then to the file xutility line 1479
// TEMPLATE FUNCTION copy
template<class _InIt,
class _OutIt> inline
_OutIt _Copy_opt(_InIt _First, _InIt _Last, _OutIt _Dest,
_Nonscalar_ptr_iterator_tag)
{ // copy [_First, _Last) to [_Dest, ...), arbitrary iterators
_DEBUG_RANGE(_First, _Last);
for (; _First != _Last; ++_Dest, ++_First)
//1479---> *_Dest = *_First;
return (_Dest);
Is there anything canged?
Roland
Re: BCB6 to BDS2006 problems with operators
Author: John Grabner
Date: Thu, 11 Oct 2007 04:44
Date: Thu, 11 Oct 2007 04:44
27 lines
1578 bytes
1578 bytes
Roland wrote:
> In BCB6 I could overload the = operator like:
>
> TMyClass& __fastcall operator=(TMyClass &p);
>
> TMyClass& __fastcall TMyClass::operator=(TMyClass &p)
> {
> for(int i = 0; i < 4; i++) {
> FEnabled[i] = p.Enabled[i];
> FPosition[i] = p.Position[i];
> }
> FMode = p.Mode;
> FDivider = p.Divider;
> return this;
> }
>
> Now in BDS2006 I get an error msg like:
> [C++ Error] xutility(1645): E2285 No match found for
> 'TMyClass::operator =(const TMyClass)'
>
It needs to be const
TMyClass& __fastcall operator=(const TMyClass &p);
should do the trick.
John.
Re: BCB6 to BDS2006 problems with operators
Author: Remy Lebeau (TeamB)
Date: Tue, 16 Oct 2007 16:56
Date: Tue, 16 Oct 2007 16:56
21 lines
1559 bytes
1559 bytes
"Roland" <neubert_nosp_@_nosp_wst.eu> wrote in message
news:470c83d5$1@newsgroups.borland.com...
> TMyClass& __fastcall operator=(TMyClass &p);
Get rid of the __fastcall convention and change the parameter to be 'const'
(which you should do anyway since you are not making any changes to it
inside the operator's body):
TMyClass& operator=(const TMyClass &p);
> return this;
You are trying to return a pointer where a reference is expected. You need
to dereference the pointer:
return *this;
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads