27-09-2009, 07:55
|
|
|
|
חבר מתאריך: 23.10.05
הודעות: 319
|
|
C++ constructor
שלום
למה במקרה הבאה לא ניתן לרשום איתחול בקונסטרוקטור בצורת הרשימה, רק בגופו ניתן?
ככה מותר:
קוד:
class area_cl{
public:
int height;
int width;
};
class cilinder: public area_cl{
public:cilinder(int h, int w){
height = h;
width = w;
}
};
וככה משום מה אסור:
קוד:
class area_cl{
public:
int height;
int width;
};
class cilinder: public area_cl{
public: cilinder(int h, int w): height(h), width(w){}
};
תגובת קומפיילר:
Error 1 error C2614: 'cilinder' : illegal member initialization: 'width' is not a base or member c:\documents and settings\fima\my documents\visual studio 2008\projects\schildt_c++\79_4\79_4\main.cpp 12
Error 2 error C2614: 'cilinder' : illegal member initialization: 'height' is not a base or member c:\documents and settings\fima\my documents\visual studio 2008\projects\schildt_c++\79_4\79_4\main.cpp 12
למה?
תודה
|