Why is it that I can declare an object of a parent class as a function or as a variable but not the same as a sub-class. The sub-class can only be declared as a function. I get the error message from the sub-class object:
Error 2 error LNK1120: 1 unresolved externals
Error 1 error LNK2019: unresolved external symbol "public: __thiscall SuperB::SuperB(void)" (??0SuperB@@QAE@XZ) referenced in function _main C
Lines 24 and 26 are not declaring objects. They're declaring functions called A and B respectively. You can't declare a default-constructed object like that.
For line 23, the linker is telling you that it can't find a default constructor for Subclass. I can see that you've declared one, but I don't see a definition anywhere in your code.
EDIT: Also, the parentheses at the end of line 4 shouldn't be there.
you can declare objects with () though it's not recommended for (a) confusion with functions and (b) prefer braced/uniform initialization
the problem you have is there are 2 objects of type Subclass called B, you also have 2 objects of type SuperA called A though one of them was always commented out and so you didn't face the same problem with SuperA.
OK , thanks
I found where the issue is.
I thought that the declaration would be enough and not the definition
I did not have the function definition and now that I have read the error message again, it makes sense.
you can declare objects with () though it's not recommended for (a) confusion with functions and (b) prefer braced/uniform initialization
Just to be clear, if you're declaring an object, using a constructor that takes arguments, then, yes, you can use parentheses. However, if you're declaring an object using the default constructor, then you cannot use parentheses, because this will be interpreted as a function declaration.
Hence, lines 24 and 26 in the OP's code are not declaring objects. They're declaring functions.