سؤال

لماذا يعطيني البرنامج التالي خطأ في الإعلان؟ ألا أعلن ذلك في هذا الخط المحدد؟

#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
هل كانت مفيدة؟

المحلول

أخطأت "bigint" ل "bitint":

class BitInt

نصائح أخرى

يتم تسمية الفصل باسم "Bitint" عندما أفترض أنه يجب أن يكون "bigint". مجرد خطأ مطبعي.

هذه مشكلتك:

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

    return 0;
}

يجب أن يكون:

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

    return 0;
}

وأنت تعلن الطبقة Bitint و في main استخدام bigint. - هناك مطبعي واحد هو ثنائيةب ثنائية أخرىجيم

على ملاحظة غير ذات صلة، فإن تحديد المليون على أنه 1000000 غير مجدولة. السبب في استخدام الثوابت المسماة هو جعل الغرض من الأرقام واضحة ويسمح لك بتغييره بسهولة، وليس فقط أن تتيح لك كتابة رقم في الكلمات بدلا من الأرقام.

سيكون من الأفضل استدعاء Bigint_Digits ثابت أو شيء ما.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top