C ++ class declaration
Why is the following program giving me a declaration error? Am I not declaring this on this particular line?
#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
0
a source to share
4 answers
In an unrelated note, defining MILLION as 1,000,000 is meaningless. The reason for using named constants is to keep the number assignment clean and allow you to easily change it, rather than just letting you enter the number in words instead of numbers.
Better would be to call the BIGINT_DIGITS constant or something.
0
a source to share