Я пытаюсь понять, почему оператор (<), определенный для этого класса, не выполняется при вызове: </p>
//File A.h (simplified class)
#ifndef __A__H
#define __A__H
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
class A {
private:
string _str;
int _number;
public:
A( string str="", int age=0): _str(str), _number(number){} //inline
int operator < (const A &a1 ) const
{
cout<<"Call of new operator <"<<endl;
if ( _str == a1._str )
return _number < a1._number;
return _str < a1._str; //here use of (<) associated to string
}
};
#endif
int main()
{
A *obj1= new A("z",10);
A *obj2= new A("b",0);
int res=obj1<obj2; //res is equal to 1. There's no message
// call of new operator"
return 0;
}
Я понял, что переопределение оператора разрешает его вызов,Любая помощь ?спасибо