Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheritance...Calling the superclass constructor 1

Status
Not open for further replies.

nexius

Programmer
Jul 8, 2000
109
0
0
CA
Hi.

I've done most of my studies in Java and so C++/Visual C++ is sometimes confusing for me.

What I want to know is how to inherit a class and create a constructor in the new class that also calls the super class's constructor... or does it do that automatically? I'm not sure.

In Java it's just "super()"

A summarized example of what I'm trying to do:


class shape
{
public:
shape(float width, float height)
{
m_width = width;
m_height = height;
}

protected:
float m_width, m_height;
}
class oval::public shape
{
public:
oval()
{
m_num_of_vertices = 20;
// do the shape constructor
}

protected:
float m_num_of_vertices;
}

VC++ won't even let me make another constructor for the class that inherits from shape(). Why?

Thanks for any feedback you have time to give,
-NeXius
 
If memory serves, the parent constructor will be called automatically if there is a default constructor in the parent class. Otherwise, you need to call it yourself with the appropriate params.

Matt
 
To add to the above.

shape::shape(x,y) ;

William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top