עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

הורשה ב ++c, לא עובר הידור. מישהו יכול לעוץ לי

Featured Replies

פורסם

עיצה ?

הקוד שלי מורכב מ header file שהוא base class כדלקמן:


//baseh.h

#ifndef mybase
#define mybase

class base
{
   public:
  base(int);
   protected:
  int first;
};
#endif

ומקובץ פונקציות למחלקה כדלקמן:


// base.cpp

#include "base.h"

base::base(int myF)
{
   first = myF;
}

ו header file למחלקה יורשת כדלקמן:


// inher.h

#ifndef myinher
#define myinher

#include "base.h"

class inher : public base
{
   public:
  inher(int, int);
   private:
  int second;
};
#endif

וקובץ פונקציות למחלקה:


// inher.cpp

//#include "base.h"
#include "inher.h"

inher::inher(int myFirst, int mySecond)
{
   first = myFirst;
   second = mySecond;
}

היישום הינו:



// temp.cpp

#include "base.h"
#include "inher.h"

int main()
{
   inher myHeritage(1,2);
   return 0;
}

פקודת ההידור הינה:

bcc52 temp.cpp base.cpp inher.cpp

והתהליך מסתיים בהודעת השגיאה:

inher.cpp 7 cannot find default constructor to initialize base class 'base' in function inher::inher(int,int)

אודה למי שיואיל לחלצני מזה ! 

פורסם

כמו שכתוב ל-Base אין קונסטרקטור דיפולטי (כזה שאינו מקבל פרמטרים) לכן כשאתה יוצר אובייקט מהמחלקה inher נקרא באופן דיפולטי קונסטרקטור דיפולטי של Base (שלא קיים).

כדי להתגבר על זה אתה צריך ברשימת איתחול בקונסטרקטור של iner לקרוא לקונסטרקטור של base שמקבל פרמטר אחד.

פורסם

או בתרגום לשפת ++C, זה מה שאתה צריך להוסיף לקובץ המימוש של המחלקה הנגזרת:


// inher.cpp

//#include "base.h"
#include "inher.h"

inher::inher(int myFirst, int mySecond)
: base(myFirst) // <- specify base class constructor to use
{
// first = myFirst; // - no need for that line anymore since the base class constructor initializes 'first'
second = mySecond;
}

פורסם
  • מחבר

תודה מקרב לב !

פורסם

אתה יכול להכניס לרשימת האתחול שלך גם אתחול עבור המשתנה SECOND, והפונ שלך תהייה רייקה.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.