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


You misspelled "BigInt" for "BitInt":



class BitInt

      

+3


a source


The class is called "BitInt" when I believe it should be "BigInt". Just a typo.



0


a source


It's your problem:

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

    return 0;
}

      

It should be:

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

    return 0;
}

      

And you declare the BitInt class and main

using BigInt - there is one type Bi t another Bi r

0


a source


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







All Articles