• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to inherit constructor in C++ class?

Red Squirrel

No Lifer
I know I've done this before, I just can't remember how to do it with C++.

Basically I have two classes:
BaseHvacAction, and the constructor has one parameter: type uk1104Connector
FurnaceHA, and the constructor has type uk1104Connector and 2 ints.

I want the FurnaceHA constructor to just dump the value of the uk1104Connector into the base class.

This is my attempt, but it's not compiling. What is the proper syntax for this? I hope this makes sense.

Code:
FurnaceHA(uk1104Connector * con,int lowtemp,int hightemp) : BaseHvacAction(con);

Surprisingly, I'm not finding much on Google about this, but I don't really know what to search for. Keep in mind this is the .h file, the actual code will be in the .cpp file. I like to keep it separate.
 
You want a member initialization list...

http://www.cprogramming.com/tutorial/initialization-lists-c++.html

But this is a private detail of the relationship between the derived and base classes, and further it is implementation. Thus it has to go in the .cpp where the constructor is defined, not in the header.

Thanks looks like I had it, but my mistake was I was putting it in the header. I declared it normally in the header and put the rest in the cpp and it works now.
 
Back
Top