views:

554

answers:

4

Why does the following program give me an declaration error? Aren't I declaring it at that specific 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
+2  A: 

You misspelled "BigInt" for "BitInt":

class BitInt
Martin Cote
And to create an instance you need to use "BigInt foo();", not "BigInt();" in main.
lothar
A: 

The class is named "BitInt" when I presume it should be "BigInt". Just a typo.

JimG
A: 

This is 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 are declaring class BitInt and in main using BigInt - there's typo one is Bi**t** the other Bi**g**

stefanB
A: 

On an unrelated note, defining MILLION as 1000000 is pointless. The reason to use named constants is to make the purpose of the number clear and allow you to change it easily, not just to let you type a number out in words instead of numerals.

It'd be better to call the constant BIGINT_DIGITS or something.