我得到的错误是
whole.cpp(384): error C2270: '==' : modifiers not allowed on nonmember functions
whole.cpp(384): error C2805: binary 'operator ==' has too few parameters
whole.cpp(384): error C2274: 'function-style cast' : illegal as right side of '.' operator
我似乎无法确定问题,所以这里是代码
这是类中的运算符实现
bool operator==(const DateC& p) const{return ( DateC::DateC()== p.DateC() );};
#include <assert.h>
int main(unsigned int argc, char* argv[])
{
DateC f(29,33,11);
DateC::testAdvancesWrap();
};
void DateC::testAdvancesWrap(void)
{
DateC d;
cout << "DateC::testAdvanceWrap()" << endl ;
cout << "*********************" << endl << endl ;
cout << "\tCHECK ADVANCE MULTIPLES:" << endl;
cout << "\t------------------------" << endl;
d.setDay(1);
d.setMonth(12);
d.setYear(1999);
prettyPrint(d);
cout << "ACTION: set date 01-Dec-1999, advance, 31 days, 1 month and 1 year ->" << endl;
d.advance(1,1,31);
assert( d == DateC(1,2,2001) );
cout << "SUCCESS" << endl;
prettyPrint(d);
cout << endl << endl;
}
其余的功能工作正常它只是assert()