Не компилируется на VC7...
От: AstralX Эстония  
Дата: 30.09.03 13:06
Оценка:
Hello All.

Начинаю программировать на С++, и сразу же напарываюсь на грабли...
Ну не хочет VC7 компилировать такое... Помогите пожалуйста найти ошибку.


#include <iostream>
#include <stdlib.h>

using namespace std;

class MyHugeInt
{
    friend ostream &operator<<(ostream &, MyHugeInt &);
public:
    MyHugeInt(long = 0);
    MyHugeInt(const char *);
    ~MyHugeInt(void);
    MyHugeInt operator+(MyHugeInt &);
private:
    short integer[30];
};

MyHugeInt::MyHugeInt(long val)
{
    int i;
    
    for (i = 0; i <= 29; i++)
        integer[i] = 0;

    for (i = 29; val != 0 && i >= 0; i--)
    {
        integer[i] = val % 10;
        val /= 10;
    }
}

MyHugeInt::MyHugeInt(const char *string)
{
    int i, j;

    for (i = 0; i <= 29; i++)
        integer[i] = 0;

    for (i = 30 - strlen(string), j = 0; i <= 29; i++, j++)
        integer[i] = string[j] - '0';
}

MyHugeInt::~MyHugeInt(void)
{
}

MyHugeInt MyHugeInt::operator+(MyHugeInt &op2)
{
    MyHugeInt temp;
    int carry = 0;

    for (int i = 29; i >= 0; i--)
    {
        temp.integer[i] = integer[i] + op2.integer[i] + carry;
        if (temp.integer[i] > 9)
        {
            temp.integer[i] %= 10;
            carry = 1;
        }
        else
            carry = 0;
    }

    return temp;
}

ostream &operator<<(ostream &output, MyHugeInt &num)
{
    int i;
    
    for (i = 0; (num.integer[i] == 0) && (i <= 29); i++)
        ;

    if (i == 30)
        output << 0;
    else
        for (; i <= 29; i++)
            output << num.integer[i];

    return output;
}

int main(int argc, char *argv[])
{
  
     MyHugeInt n1(7654321), n2(7891234),
        n3("99999999999999999999999999999"),
        n4("1"), n5;

    cout << "n1 is " << n1 << endl << "n2 is " << n2 << endl
        << "n3 is " << n3 << endl << "n4 is " << n4 << endl
        << "n5 is " << n5 << endl << endl;

    n5 = n1 + n2;
    cout << n1 << " + " << n2 << " = " << n5 << endl << endl;
    
    cout << n3 << " + " << n4 << " = " << (n3 + n4) << endl << endl;

    n5 = n1 + 9;
    cout << n1 << " + " << 9 << " = " << n5 << endl << endl;

    n5 = n2 + "10000";
    cout << n2 << " + " << "10000" << " = " << n5 << endl << endl;
 
      system("PAUSE");    
      return 0;
}


Компилятор выдаёт ошибку в:
    n5 = n1 + 9;
    cout << n1 << " + " << 9 << " = " << n5 << endl << endl;

    n5 = n2 + "10000";
    cout << n2 << " + " << "10000" << " = " << n5 << endl << endl;


Если не трудно, подскажите в чём проблема...
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.