expected constructor, destructor, or type conversion before ‘(’ token

The first constructor in the header should not end with a semicolon. #include <string> is missing in the header. string is not qualified with std:: in the .cpp file. Those are all simple syntax errors. More importantly: you are not using references, when you should. Also the way you use the ifstream is broken. I suggest learning C++ before trying to use it. … Read more

QltAW.png

Base class constructors are automatically called for you if they have no argument. If you want to call a superclass constructor with an argument, you must use the subclass’s constructor initialization list. Unlike Java, C++ supports multiple inheritance (for better or worse), so the base class must be referred to by name, rather than “super()”. … Read more

Java class “cannot be resolved to a type”

The problem is that TeamLeader appears to be an inner class (hard to tell, your indentation is bad), and since it’s not static, you can’t instantiate it by itself. You either need to make TeamLeader its own class, or make it a static class and instantiate it as Employee.TeamLeader (or whatever the parent class is, your indentation is really not helpful here).

c++: No instance of overloaded function?

You’ve not included <string> header file in stock.h header file, even though you’re using std::string in it. Maybe that is causing this error message (if that is the case, then I would say its really a bad message). Another problem is that in Stock class definition, you’ve written this: which is wrong. Remove Stock:: from it, and make it like this: Stock:: is required when defining … Read more

implicit super constructor Person() is undefined. Must explicitly invoke another constructor?

If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is … Read more

Why do C++ objects have a default destructor?

It’s wrong to say that a compiler-generated default constructor takes no action. It is equivalent to a user-defined constructor with an empty body and an empty initializer list, but that doesn’t mean it takes no action. Here is what it does: It calls the base class’es default constructor. It initializes the vtable pointer, if the … Read more

Can an abstract class have a constructor?

Yes, an abstract class can have a constructor. Consider this: The superclass Product is abstract and has a constructor. The concrete class TimesTwo has a constructor that just hardcodes the value 2. The concrete class TimesWhat has a constructor that allows the caller to specify the value. Abstract constructors will frequently be used to enforce class constraints or invariants such as … Read more