> I used to have the following:
> class CArchive
> {
> public:
[..]
> CArchive& operator<<(bool b);
> CArchive& operator<<(BYTE by);
[..]
> };
[..]
> class CArchiveEx : public CArchive
> {
> public:
[..]
> CArchiveEx& operator<<(CBBLstructArray& BBLs)
> { return ArchiveExAddArray(*this,BBLs); }
> };
This declarations hides all other operator<< from CArchive.
You can use a using declarations to reintroduce them into
the derived class scope.
using CArchive::operator<<;
> I'm now moving to VC 7.1 and I receive the following error:
> error C2678: binary '<<' : no operator found which takes a left-hand
> operand of type 'CArchiveEx' (or there is no acceptable conversion)
You should always look at the full error message. The IDE Error/Task
List window doesn't show it all. It would also help if you posted
the exact location where the error occurs.
> When I delete the method:
> CArchiveEx& operator<<(CBBLstructArray& BBLs)
> { return ArchiveExAddArray(*this,BBLs); }
>
> everything is okay.
You probably want some of the base class operator<<,
which is not found by standard name lookup rules.
-hg
danip - 30 Nov 2005 15:51 GMT
The error is:
error C2678: binary '<<' : no operator found which takes a left-hand
operand of type 'CArchiveEx' (or there is no acceptable conversion)
ArchiveEx.h(38) : see reference to function template
instantiation 'ARCHIVE &ArchiveExAddArray<CArchiveEx,ARRAY>(ARCHIVE
&,const ARRAY &)' being compiled
with
[
ARCHIVE=CArchiveEx,
ARRAY=CBBLstructArray
]
ArchiveEx.h(92) : see reference to function template
instantiation 'CArchiveEx
&ArchiveExAddArray<CArchiveEx,ARRAY>(CArchiveEx &,const ARRAY &)' being
compiled
with
[
ARRAY=CDevDBKDCstructArray
]
Let me ntify the CArchive is my own class and not the MFC one.
danip - 30 Nov 2005 15:53 GMT
The full error is:
error C2678: binary '<<' : no operator found which takes a left-hand
operand of type 'CArchiveEx' (or there is no acceptable conversion)
ArchiveEx.h(38) : see reference to function template
instantiation 'ARCHIVE &ArchiveExAddArray<CArchiveEx,ARRAY>(ARCHIVE
&,const ARRAY &)' being compiled
with
[
ARCHIVE=CArchiveEx,
ARRAY=CBBLstructArray
]
ArchiveEx.h(92) : see reference to function template
instantiation 'CArchiveEx
&ArchiveExAddArray<CArchiveEx,ARRAY>(CArchiveEx &,const ARRAY &)' being
compiled
with
[
ARRAY=CBBLstructArray
]
Let me notify that the CArchive is mine and not the MFC.
Holger Grund - 30 Nov 2005 16:12 GMT
> The full error is:
> error C2678: binary '<<' : no operator found which takes a left-hand
> operand of type 'CArchiveEx' (or there is no acceptable conversion)
> ArchiveEx.h(38) : see reference to function template
> instantiation 'ARCHIVE &ArchiveExAddArray<CArchiveEx,ARRAY>(ARCHIVE
Are you sure that this is the correct message?
It would make sense if it was ArchiveAddArray (no Ex).
This function uses
archive << nSize; // this should error
left hand type is CArchiveEx, right hand is int.
Your operator<< in CArchiveEx hides the CArchive::operator<<
overloads.
It should work if look up would be done in CArchive (e.g.)
static_cast<CArchive&>(archive) << nSize;
But what you really want in this case, is introducing the
operator<< overloads into the derived class, so that the
compiler will automatically chose the correct one.
To do so add a using declaration, into the CArchiveEx
class declaration like:
class CArchiveEx ... { ..
public:
using CArchive::operator<<;
...
};
Apparently, this is a standard conformance improvement
in VC 7.1 over VC6 bad name lookup.
-hg