שאלה c++

eyal the one

New member
שאלה c++

class a { protected: virtual int func(); }; class b : public a { protected: virtual int func(); }; class c : public b { };​
האם גם ב c אני חייב לממש את func על פי חוקי השפה?
 

galh

New member
אתה לא חייב.

חייבים לממש פונקציה רק אם היא אבסטרקטית (0=). במקרה שלך, class c יורשת את המימוש של func מ- class b.
 

eyal the one

New member
תודה רבה!!

ועוד שאלה
class a { protected: virtual int func() = 0; }; class b : public a { protected: virtual int func() = 0; }; class c : public b { protected: virtual int func() {return 1;} }​
האם מותר לעשות את זה?
 
למעלה