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.
#include <iostream>
class CBase
{
public:
CBase() : a(0), b(0), c(0) {}
CBase(int aa, int bb, int cc) : a(aa), b(bb), c(cc) {}
int a, b, c;
};
class CInterface
{
public:
CInterface(CBase &b)
: base(b), x(b.a), y(b.b), z(b.c)
{
}
int &x, &y, &z;
private:
CBase &base;
};
int main()
{
CBase base(1, 2, 3);
CInterface iface(base);
std::cout << iface.x << ' ' << iface.y << ' ' << iface.z << std::endl;
std::cout << base.a << ' ' << base.b << ' ' << base.c << std::endl;
iface.x = 99;
base.c = 88;
std::cout << iface.x << ' ' << iface.y << ' ' << iface.z << std::endl;
std::cout << base.a << ' ' << base.b << ' ' << base.c << std::endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With