Home › Forums › C Programming › Calling Base class constructor
- This topic has 0 replies, 1 voice, and was last updated 17 years, 3 months ago by serkan.
Viewing 0 reply threads
- AuthorPosts
- September 12, 2007 at 1:28 am #2001serkanParticipant
Hi,
please see the following scenario.1234567891011121314151617class base{<br />float rate;<br />public:<br />base(){}<br />};<br />class derived : public base{<br />int principal;<br />int year;<br />public:<br />derived(){}<br />derived(int _principal, int _year)//// I am not initializing the base class<br />////constructor<br />};<br />main()<br />{<br />derived d(1222,5);<br />}I have not writtent he body of the constructors. My question is I have not used the statement like derived(int _principal, int _year):base(_principal,_year)
and declared the default constructor in the base class i.e. base(){} so the compliler is calling that default constructor while I create the derived class constructor. Is there any draw back in this procedure……….?
Or always I sould call the constructor explicitly while creating the derived calss constructor and adding one more construcotor in the base class like this.1234567891011121314class base{<br />float rate;<br />public:<br />base(){}<br />base(int i, int j); ///////// additional constructor with 2 arguments<br />};<br />class derived : public base{<br />int principal;<br />int year;<br />public:<br />derived(){}<br />derived(int _principal, int _year):base(_principal,_year)<br />};<br />Please suggest
- AuthorPosts
Viewing 0 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.