#1 10.11.12 15:21
[C++] перегрузка операторов
Доброго времени суток! Возникло недопонимание. Есть абстрактный класс Integer
class Integer
{
public:
void virtual print() = 0;
friend Integer& operator +( const Integer &);
friend Integer& operator -( const Integer &);
friend Integer& operator *( const Integer &);
friend Integer& operator /( const Integer &);
Integer(){
};
virtual ~Integer(){
};
};
от него наследуется класс Decimal
class Decimal:public Integer
{
public:
void print()
{
int a = atoi(data);
cout << a;
};
Decimal& operator+( const Decimal &B)
{
int tmp1 = atoi(this->data),
tmp2 = atoi(B.data);
Decimal *Int = new Decimal(tmp1+tmp2);
return *Int;
};
Decimal& operator-( const Decimal &B)
{
int tmp1 = atoi(this->data),
tmp2 = atoi(B.data);
Decimal *Int = new Decimal(tmp1-tmp2);
return *Int;
};
Decimal& operator*( const Decimal &B)
{
int tmp1 = atoi(this->data),
tmp2 = atoi(B.data);
Decimal *Int = new Decimal(tmp1*tmp2);
return *Int;
};
Decimal(int a)
{
data = new char[10];
data = itoa(a, data, 10);
};
Decimal(){
};
~Decimal()
{
};
private:
char *data;
};
А теперь суть вопроса. friend Integer& operator /( const Integer &); ошибка при компиляции - IntelliSense: слишком мало параметров для этой функции оператора. Я даже не могу понять где тут костыль. Остальные операторы работают норм.
Offline

