-1

次のプログラムで宣言エラーが発生するのはなぜですか? その特定の行で宣言していませんか?

#include <iostream>

#define MILLION 1000000

using namespace std;

class BitInt

{
  public:
    BigInt();

  private:
    int digit_array[MILLION];
    int length;
};

BigInt::BigInt()
{
    int length=0;
    for(int i=0; i<MILLION; i++)
        digit_array[i]=0;
}

int main()
{
    BigInt();

    return 0;
}

bigint.cpp:11: error: ISO C++ forbids declaration of ‘BigInt’ with no type
bigint.cpp:18: error: ‘BigInt’ has not been declared
bigint.cpp:18: error: ISO C++ forbids declaration of ‘BigInt’ with no type
bigint.cpp: In function ‘int BigInt()’:
bigint.cpp:22: error: ‘digit_array’ was not declared in this scope
4

4 に答える 4

3

「BitInt」の「BigInt」のつづりを間違えました:

class BitInt
于 2009-05-21T03:05:31.473 に答える
0

クラスの名前は「BitInt」ですが、「BigInt」であるべきだと思います。ただのタイプミス。

于 2009-05-21T03:06:36.400 に答える
0

これとは関係ありませんが、MILLION を 1000000 と定義しても意味がありません。名前付き定数を使用する理由は、数値の代わりに単語で数値を入力できるようにするためだけでなく、数値の目的を明確にし、簡単に変更できるようにするためです。

定数 BIGINT_DIGITS などを呼び出す方がよいでしょう。

于 2010-02-04T02:05:04.830 に答える
0

これはあなたの問題です:

int main()
{
    BigInt();     // <--- makes no sense

    return 0;
}

そのはず:

int main()
{
    BigInt bigint; // create object of a class

    return 0;
}

そして、あなたはクラスBitIntを宣言していてBigIntmain使用しています- タイプミスがあります

于 2009-05-21T04:41:03.620 に答える