Considering the following code/scheme provided below, is it somehow possible to omit the necessity to specify the this
?
Is there a way to change the code so that a function/constructor automatically get the surrounding scope, maybe even as a template argument?
#include <iostream>
class AttrBase{
public:
virtual int g()const = 0;
};
class ABase{
public:
void reg(const char* name, AttrBase* att){
std::cout << name << ": " << att->g()<< std::endl;
}
};
class Attr : public AttrBase{
public:
Attr(const char* name, int val, ABase* parent /* = this */) // something like this
:v(val)
{
parent->reg(name, this);
};
int g()const override{return v;};
int v;
};
class D:public ABase{
Attr a{"a", 1, this};
Attr b{"b", 2, this};
Attr c{"c", 3}; //< is this somehow possible
};
int main(){
D d;
}