0

I have two classes and I want to inherit one of them that has a constructor with a parameter but, I get errors.

First Class:

class stack{
 stack(int variable){

}

...code...
};

Second class:

class Expression : public stack{

//class constructor
Expression(){

}

...code...

};

the errors I get...

In constructor 'Expression::Expression()':error: no matching function for call to 'stack::stack()'

note: candidate: stack::stack(int)

note: candidate expects 1 argument, 0 provided

note: candidate: constexpr stack::stack(const stack&)

note: candidate: constexpr stack::stack(stack&&)

Awab Eldaw
  • 23
  • 8

1 Answers1

0

I have searched online I didn't find anything that helps me to resolve these errors.

but after many tries, I have found the solution...and if you have a better way to resolve these errors or to describe my solution in better words or more scientific words please share.

Solution: The issue was in the syntax...The second class "Expression" that inherited from the stack class should have a constructor defined as below...

class Expression : public stack{

  // How the constructor should be defined.
  Expression():stack(parameter_value){

}

...code...
};

So, the whole code will be like:

class stack{
 stack(int variable){

}

...code...
};

class Expression : public stack{

  // How the constructor should be defined.
  Expression():stack(parameter_value){

}

...code...
};
Awab Eldaw
  • 23
  • 8