Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Post by Michael Ke » Fri, 29 Mar 2002 06:37:25



Hi,

I'm having trouble with my MSVC program compiling in that I keep
getting C2784 errors relating to operator == and operator < (less
than) for a group of classes.  Below is an overview of the program I'm
fighting with.

Note that I don't use either operator == or operator < anywhere in my
program (relating to the classes I create).

I'm using MSVC 6.0, SP5

Anyone know as to what the heck is going on?

thanks,
mike
---------------------

#include <map>
#include <string>

using namespace std;

class CPart{
public:
        CPart();
        ~CPart();
        CPart(const CPart &Rhs);
        const operator =(const CPart &Rhs);
        int m_nMemberInfo;

Quote:}

class CGroup{
public:
        CGroup();
        ~CGroup();
        CGroup(const CGroup &Rhs);
        const operator =(const CPart &Rhs);
        int m_nItem;
Quote:}

// I'll spare the implementation of assignment and copy
// constructor, but it looks like:
// this->m_nMemberInfo = Rhs.m_nMemberInfo;
// ...etc

int main(){
        typedef map<string, CPart> MAPITEMS;
        pair<string, CPart> pscInsertItem;        

        CPart cpTemp;
        cpTemp.m_nMemberInfo = 4;

        pscInsertItem.second = cpTemp;
        pscInsertItem.first = string("ItemOne");

        MAPITEMS mscAllIItems;
        mscAllItems.insert(pscInsertItem);      // C2784

        // removing the above line and just
        // adding the following two lines will also
        // generate a C2784

        // std::vector<int> v;
        // v.push_back(24);

Quote:}

 
 
 

Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Post by Michael Ke » Fri, 29 Mar 2002 06:44:15


Quote:

>class CGroup{
>public:
>    CGroup();
>    ~CGroup();
>    CGroup(const CGroup &Rhs);
>    const operator =(const CPart &Rhs);
>    int m_nItem;
>}

correction on the assignment operator -- my mistake

const operator =(const CGroup &Rhs);

 
 
 

Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Post by Victor Bazaro » Fri, 29 Mar 2002 07:16:32



> Hi,

> I'm having trouble with my MSVC program compiling in that I keep
> getting C2784 errors relating to operator == and operator < (less
> than) for a group of classes.  Below is an overview of the program I'm
> fighting with.

What is C2784?  If you expect us to know that, you ought to
post in the microsoft.public.vc.language newsgroup.  This
newsgroup is NOT VC++-specific.

Quote:

> Note that I don't use either operator == or operator < anywhere in my
> program (relating to the classes I create).

> I'm using MSVC 6.0, SP5

> Anyone know as to what the heck is going on?

> thanks,
> mike
> ---------------------

> #include <map>
> #include <string>

> using namespace std;

> class CPart{
> public:
> CPart();
> ~CPart();
> CPart(const CPart &Rhs);
> const operator =(const CPart &Rhs);

What does the operator = return?  'const' WHAT?

Quote:> int m_nMemberInfo;
> }

Missing semicolon here.

Quote:

> class CGroup{
> public:
> CGroup();
> ~CGroup();
> CGroup(const CGroup &Rhs);
> const operator =(const CPart &Rhs);

Same question here, 'const' WHAT?

Quote:> int m_nItem;
> }

Missing semicolon here.

- Show quoted text -

Quote:> // I'll spare the implementation of assignment and copy
> // constructor, but it looks like:
> // this->m_nMemberInfo = Rhs.m_nMemberInfo;
> // ...etc

> int main(){
> typedef map<string, CPart> MAPITEMS;
> pair<string, CPart> pscInsertItem;

> CPart cpTemp;
> cpTemp.m_nMemberInfo = 4;

> pscInsertItem.second = cpTemp;
> pscInsertItem.first = string("ItemOne");

> MAPITEMS mscAllIItems;
> mscAllItems.insert(pscInsertItem); // C2784

> // removing the above line and just
> // adding the following two lines will also
> // generate a C2784

> // std::vector<int> v;
> // v.push_back(24);

Well, did you include <vector>?

Quote:

> }

Post _real_ code so that we can copy and paste it into a text
file and try compiling it.  Don't _retype_ your code into your
message.  Copy-and-paste it.

Victor
--
Please remove capital A's from my address when replying by mail

 
 
 

Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Post by John Harriso » Fri, 29 Mar 2002 07:26:13



Quote:> Hi,

> I'm having trouble with my MSVC program compiling in that I keep
> getting C2784 errors relating to operator == and operator < (less
> than) for a group of classes.  Below is an overview of the program I'm
> fighting with.

> Note that I don't use either operator == or operator < anywhere in my
> program (relating to the classes I create).

> I'm using MSVC 6.0, SP5

> Anyone know as to what the heck is going on?

> thanks,
> mike
> ---------------------

> #include <map>
> #include <string>

> using namespace std;

> class CPart{
> public:
> CPart();
> ~CPart();
> CPart(const CPart &Rhs);
> const operator =(const CPart &Rhs);

This is not a legal declaration. Try this

CPart& operator=(const CPart& rhs);

perhaps you are confusing your compiler?

john

- Show quoted text -

Quote:> int m_nMemberInfo;
> }

> class CGroup{
> public:
> CGroup();
> ~CGroup();
> CGroup(const CGroup &Rhs);
> const operator =(const CPart &Rhs);
> int m_nItem;
> }
> // I'll spare the implementation of assignment and copy
> // constructor, but it looks like:
> // this->m_nMemberInfo = Rhs.m_nMemberInfo;
> // ...etc

> int main(){
> typedef map<string, CPart> MAPITEMS;
> pair<string, CPart> pscInsertItem;

> CPart cpTemp;
> cpTemp.m_nMemberInfo = 4;

> pscInsertItem.second = cpTemp;
> pscInsertItem.first = string("ItemOne");

> MAPITEMS mscAllIItems;
> mscAllItems.insert(pscInsertItem); // C2784

> // removing the above line and just
> // adding the following two lines will also
> // generate a C2784

> // std::vector<int> v;
> // v.push_back(24);

> }

 
 
 

Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Post by Michael Ke » Fri, 29 Mar 2002 08:05:46


<snipsnip>
Quote:>This is not a legal declaration. Try this

>CPart& operator=(const CPart& rhs);

>perhaps you are confusing your compiler?

>john

<snip>

Could be.  I'll try that.  I've always done my declarations that way
and they seem to work fine.

Quote:>> int m_nMemberInfo;
>> }

>> class CGroup{
>> public:
>> CGroup();
>> ~CGroup();
>> CGroup(const CGroup &Rhs);
>> const operator =(const CPart &Rhs);
>> int m_nItem;
>> }
>> // I'll spare the implementation of assignment and copy
>> // constructor, but it looks like:
>> // this->m_nMemberInfo = Rhs.m_nMemberInfo;
>> // ...etc

>> int main(){
>> typedef map<string, CPart> MAPITEMS;
>> pair<string, CPart> pscInsertItem;

>> CPart cpTemp;
>> cpTemp.m_nMemberInfo = 4;

>> pscInsertItem.second = cpTemp;
>> pscInsertItem.first = string("ItemOne");

>> MAPITEMS mscAllIItems;
>> mscAllItems.insert(pscInsertItem); // C2784

>> // removing the above line and just
>> // adding the following two lines will also
>> // generate a C2784

>> // std::vector<int> v;
>> // v.push_back(24);

>> }

 
 
 

Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Post by Michael Ke » Fri, 29 Mar 2002 08:13:24


On Wed, 27 Mar 2002 22:16:32 GMT, "Victor Bazarov"



>> Hi,

>> I'm having trouble with my MSVC program compiling in that I keep
>> getting C2784 errors relating to operator == and operator < (less
>> than) for a group of classes.  Below is an overview of the program I'm
>> fighting with.

>What is C2784?  If you expect us to know that, you ought to
>post in the microsoft.public.vc.language newsgroup.  This
>newsgroup is NOT VC++-specific.

C2784:

To quote from Microsoft Support Services --
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q166721

"SYMPTOMS
When you attempt to instantiate an STL container such as vector or
list, you receive compiler error C2784 if the class type of the
objects contained do not have operator < and operator == defined to
take the class type as both arguments: "

I don't use either operator, and creating them does not solve the
problem.

The thing is that my source code particular unremarkable - if I have
this very problem with just two lines (the vector example). There is
something seriously wrong with either my headers, or libraries.  I was
hoping for someone who has experienced this particular problem.

I'll post the actual source code.  I'll also try the microsoft news
groups.

mike

 
 
 

Problem with: MSVC 6 Problem with STL <map>, Templates and C2784 -- help please

Post by P.J. Plauge » Fri, 29 Mar 2002 09:47:05



> "SYMPTOMS
> When you attempt to instantiate an STL container such as vector or
> list, you receive compiler error C2784 if the class type of the
> objects contained do not have operator < and operator == defined to
> take the class type as both arguments: "

> I don't use either operator, and creating them does not solve the
> problem.

Are you sure? IIRC, VC++ erroneously insists on instantiating member
functions that it does not use. Unfortunately, the library implements
operator== and operator< for several of the containers as member
functions, not just as external template functions. The usual fix is
to implement the comparisons of the proper form for the element type.
Perhaps they do not take const arguments?

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com

 
 
 

1. HELP >>>>>>>>>>>>> WINAPI <<<<<<<<<<<<<<<<<

   I need help in writting a vb program that will monitor the message
queue of another aplication that is running along with my program. Itried
to use PeekMessage api function but the help file says that it can only
peek the application's own message queue.  My program is similar in
working with SPY or the SPY++ program. Is there an api function that Ican
use. PLEEEEEEEEEZE help.

2. HELP: Monitoring the network

3. >>>>>>>>> PROBLEM WITH MSICPB.EXE <<<<<<<<<<<<<<<<<

4. Elk Systems

5. HELP >>> ActiveMovie SDK problems <<< HELP

6. Magic Sac

7. <<<<<<Programmers Needed>>>>>>>

8. Quesion about email solutions & sizing

9. <<>><><><><><><><><><><>

10. <><><> www.FotoCD.net <><><>

11. HELP >>>>>>>>>WIN API <<<<<<<<<<<

12. ************************<<<<<<LOTUS CORP.SUCKS>>>>>*****************