Click here to Skip to main content
15,850,548 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is it posible for a derive class to call a constructr of base class like that
rectstyle = new Rectangle(double a,double b);

rectstyle is object of derive class
rectangle is base class
Updated 27-Aug-13 23:42pm
John-ph 28-Aug-13 5:00am    
A derived class inherits the behaviours of a base class which means a child inherits the characteristics of a parent. it's possible, right? Think the other way round. Actually in the above code you are not trying call the constructor but you are trying to assign an instance of base class object to its' own child which is not possible.
Innocent910 28-Aug-13 5:53am    
ok thnx

Derived class can call base constructor only in their own constructor, see, for instance:
Share this answer
Just do this...

In your rectstyle class create a constructor like this

public rectstyle(double a, double b)
:base (a,b)


Then just create the object like this...

rectstyle = new rectstyle (double a,double b);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900