jeudi 14 janvier 2021

Why can't access parent attributes if the parent class uses child template parameters as template arguments? [duplicate]

Why can't access parent attributes if I use template parameters as parent template arguments?

It's difficult to formulate this question, in its simplest form, why the following snippet does not compile? Is there any way to make this thing work? what am I doing wrong?

Live example

template<typename T>
struct Str{ T x; };

template<typename T>
class Cls : public Str<T>{
    Cls(){
        x = 0; // Error: 'x' was not declared in this scope 
    }
};

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire