I would like to "rename" some members of my class ofVec4f
.
I know it's impossible in strict C++ but could I create a new class that inherits from my class and declare new members which are aliases or pointers to the original members?
I tried the following:
class ofVec4fGraph : public ofVec4f {
public :
float& minX;
float& maxX;
float& minY;
float& maxY;
ofVec4fGraph(float _minX,float _maxX, float _minY, float _maxY )
: minX(_minX), maxX(_maxX), minY(_minY), maxY(_maxY)
{ ofVec4f(_minX, _maxX, _minY, _maxY); };
};
I think this may be what you want.
Your class should be:
Constructor chaining is not possible in
C++
. You use initializer list to initialize base class.You can now use this as:
Not necessarily.
Proper Inheritance dictates that you only inherit publicly when the derived class is substitutable for base class. In this case you are implementing derived class in terms of base class, here the preferred approach is to use private inheritance, or yet better object composition. And composition is better than inheritance. You should either use the approach described by @Michael J, or use private inheritance.
Also learn why public data member is bad