parameter passing to base class constructor (definition and delcaration)

V

Vasileios

Hello everyone,

I have a very simple question.

Imagine that I have a CBase class with a nondefault constructor that
takes one argument CBase::CBase(int A)

And a derived class CDerived that takes two arguments.

If I am not mistaken the definition of the constructor of CDerived
should be:

CDerived::CDerived(int A, int B) : CBase(A){ }


My question is, what should the declaration of CDerived should look like
(in the .h file)?


Thank you
Vasileios
 
F

Frank Schmitt

Vasileios said:
Hello everyone,

I have a very simple question.

Imagine that I have a CBase class with a nondefault constructor that
takes one argument CBase::CBase(int A)

And a derived class CDerived that takes two arguments.

If I am not mistaken the definition of the constructor of CDerived
should be:

CDerived::CDerived(int A, int B) : CBase(A){ }


My question is, what should the declaration of CDerived should look
like (in the .h file)?

class CDerived: public CBase {
public:
CDerived(int A, int B);
};

HTH & kind regards
frank
 
J

jeffc

Vasileios said:
Hello everyone,

I have a very simple question.

Imagine that I have a CBase class with a nondefault constructor that
takes one argument CBase::CBase(int A)

And a derived class CDerived that takes two arguments.

If I am not mistaken the definition of the constructor of CDerived
should be:

CDerived::CDerived(int A, int B) : CBase(A){ }

My question is, what should the declaration of CDerived should look like
(in the .h file)?

class CDerived : public CBase
{
public:
CDerived(int, int);
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,051
Members
48,769
Latest member
Clifft

Latest Threads

Top