c++ - Template inheritance and a base member variable -
i weird error when trying use template inheritance. code:
template <class t> class { public: int {2}; a(){}; }; template <class t> class b : public a<t> { public: b(): a<t>() {}; void test(){ std::cout << "testing... " << << std::endl; }; };
and error:
error: use of undeclared identifier 'a'; did mean 'std::uniform_int_distribution<long>::a'? void test(){ std::cout << "testing... " << << std::endl; }
and in case affect use these flags:
-wall -g -std=c++11
i don't know wrong since same code pure classes without templating works fine.
i don't know wrong since same code pure classes without templating works fine.
this because base class (class template a
) not nondependent base class, type can't determined without knowing template arguments. , a
nondependent name. nondependent names not looked in dependent base classes.
to correct code, make name a
dependent, dependent names can looked @ time of instantiation, @ time exact base specialization must explored , known.
you could
void test() { std::cout << "testing... " << this->a << std::endl; };
or
void test() { std::cout << "testing... " << a<t>::a << std::endl; };
or
void test() { using a<t>::a; std::cout << "testing... " << << std::endl; };
Comments
Post a Comment