I have a class Sphere that inherits from class Shape (for a homework project):
Within Shape I have three constructors. The declarations from Shape.h are as follows:
Shape();
Shape(Vector);
Shape(Vector, float[]);
Within Sphere my constructors inherit from these constructors. The declarations in my Sphere.h file are as follows:
Sphere(): Shape() {}//line 17
Sphere(Vector, float): Shape(Vector) {}//line 18
Sphere(Vector, float, float[]): Shape(Vector, float[]) {}//line 19
My syntax here is based largely on looking at templates. While my first language was C++, I was unfortunately taught other concepts, like inheritance, only in Java.
Anyway, I have the following error messages upon `make’:
Sphere.h: In constructor ‘Sphere::Sphere(Vector, float)’:
Sphere.h:18: error: expected primary-expression before ‘)’ token
Sphere.h: In constructor ‘Sphere::Sphere(Vector, float, float*)’:
Sphere.h:19: error: expected primary-expression before ‘,’ token
Sphere.h:19: error: expected primary-expression before ‘float’
Can you help me understand these messages and what might be causing them? I first tried letting them be expressed in the typical way, i.e., instead of
Sphere(): Shape();
and then describing the constructor itself in the .cc file, I did as I had seen done in some online tutorials, without really understanding why:
Sphere(): Shape() {}
This didn’t change anything, the problem remained. Thanks for your help!
You need to specify names, not just types, for the parameters, and pass the names, not the types. For example: