Class C++;类声明

Class C++;类声明,class,declaration,Class,Declaration,为什么下面的程序会给我一个声明错误? 我不是在那一行申报吗 #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

为什么下面的程序会给我一个声明错误? 我不是在那一行申报吗

#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
#包括
#定义百万1000000
使用名称空间std;
班级尖刻
{
公众:
BigInt();
私人:
整数位数组[百万];
整数长度;
};
BigInt::BigInt()
{
整数长度=0;
对于(int i=0;i您将“BigInt”拼错为“BitInt”:

您将“BigInt”拼错为“BitInt”:

当我假定该类应为“BigInt”时,该类被命名为“BitInt”。只是一个输入错误。

当我假定该类应为“BigInt”时,该类被命名为“BitInt”。只是一个输入错误。

这是您的问题:

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

    return 0;
}
您正在使用BigInt声明类BitInt,并在
main
中使用BigInt-有一个输入错误是Bit另一个是Big

这是您的问题:

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

    return 0;
}

您正在使用BigInt声明类BitInt,并在
main
中使用BigInt-有一个输入错误,一个是Bit,另一个是Big

在一个不相关的注释上,将百万定义为1000000是毫无意义的。使用命名常量的原因是为了明确数字的用途,并允许您使用c轻松地挂起来,而不仅仅是让你用文字而不是数字来输入数字


最好调用常量BIGINT_DIGITS或其他东西。

在不相关的注释中,将百万定义为1000000是毫无意义的。使用命名常量的原因是为了明确数字的用途,并允许您轻松更改它,而不仅仅是让您用文字而不是数字键入数字


最好调用常量BIGINT_DIGITS或其他东西。

要创建实例,您需要在main中使用“BIGINT foo();”而不是“BIGINT();”。要创建实例,您需要在main中使用“BIGINT foo();”而不是“BIGINT();”。
int main()
{
    BigInt bigint; // create object of a class

    return 0;
}