[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

compiler error C2678

Trying to compile this project in VS 7, and I'm getting this error:

e:\Program Files\Vc7\atlmfc\include\afxtempl.h(154): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const CVideoAdapter' (or there is no acceptable conversion)

Looked thru CVideoAdapter class, couldn't find any == comparison being made.
What am I looking at here?

Below is the line from afxtempl.h that compiler complains about:


template<class TYPE, class ARG_TYPE>
BOOL AFXAPI CompareElements(const TYPE* pElement1, const ARG_TYPE* pElement2)
{
      ASSERT(AfxIsValidAddress(pElement1, sizeof(TYPE), FALSE));
      ASSERT(AfxIsValidAddress(pElement2, sizeof(ARG_TYPE), FALSE));

      return *pElement1 == *pElement2; <------------------------------------------- the line
}

Any help is appreciated.
0
jd9288
Asked:
jd9288
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
jkrCommented:
Can you post the collection declaration where you are using 'CVideoAdapter' in and if this class has base classes?

You might need to provide your own global

BOOL operator==(const CVideoAdapter& l, const CVideoAdapter& r) {

    // evaluate some criteria that could make two CVideoAdapters 'equal'

    return TRUE;
}
0
 
AxterCommented:
>>Looked thru CVideoAdapter class, couldn't find any == comparison being made.
>>What am I looking at here?

It looks like the code is using an MFC container class like CMap.

If you're using a sorted container class, then you'll need to provide the operator in order to use your class with the sorted container.
0
 
jd9288Author Commented:
Here it is. The code is not mine, which complicates things.

class DLL_CLASS CVideoAdapterList : public CList<CVideoAdapter, CVideoAdapter&>  
{
public: // Methods
      //////////////////////////////////
      // Standard contructor/destructor
      //////////////////////////////////
      CVideoAdapterList();
      virtual ~CVideoAdapterList();

};

This supposedly is working in MS Visual C++ 6
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pb_indiaCommented:
How is this CVideoAdapter defined?
Are you making "==" calls on tjis class?
0
 
AxterCommented:
Because of your CList inheritance, you need to provide the operator== for class CVideoAdapter
0
 
jkrCommented:
As I wrote, supply a

BOOL operator==(const CVideoAdapter& l, const CVideoAdapter& r) {

   // evaluate some criteria that could make two CVideoAdapters 'equal'

   return TRUE;
}

for CVideoAdapter and add

friend operator==(const CVideoAdapter& l, const CVideoAdapter& r);

to that class' declaration.
0
 
jd9288Author Commented:
That solves the problem.
Any idea as to why it would compile in VS 6, but not VS 7?
0
 
AxterCommented:
VC7 is more compliant with the standard then VC6.

0
 
jkrCommented:
VC7 is a bit more strict than VC6, that's the only idea I can offer...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now