|
不好意思!
请教VC程序,是MSDN中的代码。#include <iostream>
#include <functional>
//#include <afx.h>
using namespace std ;
class MathOps : public plus<int>, public minus<int>,
public multiplies<int>, public divides<int>,
public modulus<int>
{
public:
int value;
MathOps(){value=0;}
MathOps(int x){value=x;}
result_type operator+(second_argument_type add2)
{return value + add2;}
result_type operator-(second_argument_type sub2)
{return value - sub2;}
result_type operator*(second_argument_type mult2)
{return value * mult2;}
result_type operator/(second_argument_type div2)
{return value / div2;}
result_type operator%(second_argument_type mod2)
{return value % mod2;}
friend ostream& operator<<(ostream& os, const MathOps& obj ) ;
};
ostream& operator<<(ostream& os, const MathOps& obj )
{
os << obj.value ;
return os ;
}
void main()
{
MathOps one,two,three,four,five,six;
// CArchive ar;
cout << "Using MathOps class..." << endl ;
//ar.Write(&one,sizeof(one));
one = 18;
cout << "one = " << one << endl ;
two = one + 1;
cout << "two = one + 1 = " << two << endl ;
three = two - 2;
cout << "three = two - 2 = " << three << endl ;
four = three * 3;
cout << "four = three * 3 = " << four << endl ;
five = four / 4;
cout << "five = four / 4 = " << five << endl ;
six = five % 5;
cout << "six = five % 5 = " << six << endl ;
}
错误是:
error C2593: 'operator <<' is ambiguous
即对象的ambiguity状态
请指教! |
|