c++ - calling a template function on a auto type-inferred variable in a template class -


this question has answer here:

this problem occurred in context of google test framework typed test cases. here inheritance , templates mixed such have refer members of base class via this->. short code below problem boils down to.

the following code not compile on gcc-4.9.2,gcc-5.1.0,clang-3.5 if first definition (1) ref used. clang not compile if second version (2) used. compile fine if actual type used in (3) (tested on http://gcc.godbolt.org/ ).

my question if compiler(s) right not compile , why right. or if formed c++11.

#include <iostream> struct {     template<int e> void foo() { std::cout << e << std::endl; }     void bar(){} }; template<typename t> struct b {     a;     void baz() {         auto& ref = this->a; // (1)         // auto& ref = a;       // (2)         // a& ref = this->a;    // (3)         static_assert(std::is_same<decltype(ref),a&>::value,                        "ref should have type a&");         ref.bar();         ref.foo<1>(); // line causes compile error     } };  int main() {     b<int> b; } 

the compiler doesn't know ref.foo template, need tell it:

ref.foo<1>(); //change ref.template foo<1>(); 

the syntax bit bizarre, have @ this question more details.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -