• 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.

C++ programming help

Stealth1024

Platinum Member
Alright I've programmed in java for a while and I'm working on a project in C++.

C++ doesn't have interfaces as far as I can tell, but I think I can do about the same thing by creating a purely virtual .h header file with a class description and then create subclass .h/.cpp pairs from this?

My questions have to do with the constructors. Should they be declared virtual? I will not have a constructor of the same name in my implementing classes.

I did read that the destructor should be virtual so it knows to execute the subclass's deconstructor.

I have looked at several guides online but no one gives examples with seperate .h and .cpp files and thus I'm not sure where I need which included, etc.

Basically I'm creating a puzzle interface, with several puzzles that implement it. And there's a solver class that is expecting any given puzzle but it doesn't know which one. Since all puzzles have the same methods, it can use generic algorythms to solve any puzzle that conforms to this interface.

I even got all the hard work done with pointers, the STL, solver class written and tested, etc....

- confused C++ programmer
 
You are describing a "mixin class" -- which is the C++ equivalent of a Java interface. The constructor does not need to be virtual.
 
Originally posted by: dwell
You are describing a "mixin class" -- which is the C++ equivalent of a Java interface. The constructor does not need to be virtual.

I would go so far as to say it shouldn't be virtual unless you plan on making it an abstract class and to only use types of its children. I wouldn't make it virtual if your interface is going to house variables that you need to access.

-silver
 
Back
Top