Here's a fairly short .cpp program that defines a simple class, implements its == operator, creates a list from the CList template, and adds some instances to the list. The program shows the == operator works as expected and that the list appears to work as expected: List members can be added and retrieved.
But when attempting to call the CList Find() function, the compiler complains:
"error C2678: binary
==: no operator found which takes a left-hand operand of typeconst COpFunc(or there is no acceptable conversion)"
I'm guessing the "left-hand operand" in the error message refers to the this-> in the == operator. If that's the case, I don't see how to fix the problem. If not, can anyone please point out the error in the code?
#include "stdafx.h"
#include <stdint.h>
///////////////////////////////////////////////
// Define a class with a constructor, two
// data members, and a == operator
//
class COpFunc
{
public:
  COpFunc();
  COpFunc( uint32_t opAddr, char opFlag );
  uint32_t addr;
  char     allocFlag;
  BOOL operator == ( COpFunc& f2 )
  {
    return ( this->addr == f2.addr ) && ( this->allocFlag == f2.allocFlag );
  }
};
COpFunc::COpFunc( uint32_t opAddr, char opFlag )
{
  addr      = opAddr;
  allocFlag = opFlag;
};
COpFunc::COpFunc()
{
};
///////////////////////////////////////////////
// Define a list of the COpFunc class
//
CList<COpFunc,COpFunc&> ops;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
  HMODULE  hModule = ::GetModuleHandle(NULL);
  POSITION pos;
  COpFunc  temp;
  if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
    return 1;
///////////////////////////////////////////////
// Create two instances of COpFunc
//
  COpFunc t1( 0x1000, 'a' );
  COpFunc t2( 0x1000, 'a' );
///////////////////////////////////////////////
// Test the == operator
//
  if( t1 == t2 )
    TRACE( "Test 1\n" );      // yep...
  t1.addr = 0x2000;
  if( t1 == t2 )              // nope...
    TRACE( "Test 2\n" );
///////////////////////////////////////////////
// Add the instances to the list
//
  ops.AddTail( t1 );
  ops.AddTail( t2 );
///////////////////////////////////////////////
// Dump the list
//
  pos = ops.GetHeadPosition();
  while( NULL != pos )
  {
    temp = ops.GetNext( pos );
    TRACE( "func: %08x %c\n", temp.addr, temp.allocFlag );
  }
///////////////////////////////////////////////
// Farkle
//
//  pos = ops.Find( t1 );
    return 0;
}
 
     
    