473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

CArray changes in VC 2003 vs VC 6.0

Hi,
I used to have the following:
class CArchive
{
public:
// create and specify the filename to use
CArchive(CString filename, DWORD size);
virtual ~CArchive();

CArchive& operator<<(bool b);
CArchive& operator<<(BYTE by);
CArchive& operator<<(WORD w);
CArchive& operator<<(LONG l);
CArchive& operator<<(DWORD dw);
CArchive& operator<<(float f);
CArchive& operator<<(double d);
CArchive& operator<<(int i);
CArchive& operator<<(short w);
CArchive& operator<<(char ch);
CArchive& operator<<(unsigned u);
CArchive& operator<<(const CString& s);

};

//template function to write array to the archive
template <class ARCHIVE, class ARRAY>
ARCHIVE& ArchiveAddArray(ARCHIVE& archive, const ARRAY& array)
{
int nSize = array.GetSize();
archive << nSize;
for(int n=0; n< nSize; n++)
{
archive << array[n];
}

return archive;
}

struct BBLStruct
{
CString m_str1;
CString m_str2;
CString m_str3;
};

class CBBLstructArray : public CArray<BBLStruct, BBLStruct&>
{
};
class CArchiveEx : public CArchive
{
public:
CArchiveEx(CString filename, DWORD size)
: CArchive(filename, size) {}
virtual ~CArchiveEx() {}

CArchiveEx& operator<<(CBBLstructArray& BBLs)
{ return ArchiveExAddArray(*this,BBLs); }
};

template <class ARRAY>
CArchiveEx& ArchiveExAddArray(CArchiveEx& self, const ARRAY& array)
{
ArchiveAddArray(self, array);
return self;
}

in VC++ 6.0 and everything worked okay.

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)

When I delete the method:
CArchiveEx& operator<<(CBBLstructArray& BBLs)
{ return ArchiveExAddArray(*this,BBLs); }

everything is okay.

What changed in templates in VC 7.1 ? and solutions ?

Thanks

-- Dani

Nov 30 '05 #1
4 2361
"danip" <da***@ecmed.com> wrote
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
Nov 30 '05 #2
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.

Nov 30 '05 #3
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.

Nov 30 '05 #4
"danip" <da***@ecmed.com> wrote
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
Nov 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ishira | last post by:
Here is a snippet of my program. It is really intresting... PREMISE: Class CobjA has a private CARRAY memeber m_Arr of objects CobjB. Class CobjB is a class with an int data variable called...
2
by: Ishira | last post by:
Hello, Please help. I am seriously at my wits end. Just when I feel I have completely understood copy contructor, I am stumped yet again. I have a class which has a CARRAY of objects. I am...
66
by: Mike Stenzler | last post by:
I am new to Template programming and I would like to create an array of user-defined class objects using MFC CArray. Normally I would use linked list processing - create an object class and then an...
0
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 ...
5
by: Silly | last post by:
I have a legacy dll that has an important function that takes a CArray<WORD,WORD>& as it's only parameter. The dll is used by a number of internal applications and so can't be changed. I am...
0
by: Josh McFarlane | last post by:
I'm currently reading raw data files for two arrays of floating point numbers. There are about 10k floating points per array per file, and I want to combine each file's arrays into a master...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
10
by: fei.liu | last post by:
Consider the following sample code char * ptr = "hello"; char carray = "hello"; int main(void){ } What does the standard have to say about the storage requirement about ptr and carray? Is...
2
by: Dymus | last post by:
Ok here is sample of code: CArray <MyClass,MyClassarr; MyClass * obj; obj = new MyClass(); obj->some_field=some_value; arr.Add((*obj)); delete obj; ----
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.