ambiguous - Why G++ cannot resolve the scope of this apparently easy ambiguity when attempting to polymorphysm with CRTP? -


i attempting create template classes each can solve specific facet of problem able mishmash them without resorting creating traditional abstract virtual classes. that, believe crtp best paradigm. however, when using crtp bit more found trapped on weak resolution logic - compiler (g++ 4.8.2) cannot distinguish between 2 methods on different classes though signature different - method name same.

the classes implementation:

template< class t > class { public:     void foo( uint32_t val ) {         t* me = static_cast<t*>( );         me->doit();     } };  template< class t > class b { public:     void foo() {         uint32_t v32 = 10;         t* me = static_cast<t*>( );         me->foo( v32 );     } };  class derived : public a<derived>,                 public b<derived> { public:     void doit() {         std::cout << "here" << std::endl;     } }; 

then used

derived d; d.foo(); 

when compiled, error surfaces:

$ g++ -std=c++11 -c testlambda.cpp  testlambda.cpp: in function ‘int main(int, char**)’: testlambda.cpp:102:7: error: request member ‘foo’ ambiguous  d.foo();    ^ testlambda.cpp:25:10: note: candidates are: void b<t>::foo() [with t = derived]     void foo() {       ^ testlambda.cpp:16:10: note:                 void a<t>::foo(uint32_t) [with t = derived; uint32_t = unsigned int]      void foo( uint32_t val ) { 

is compiler bug or actual expected result?

user pubby8 @ reddit.com/r/cpp responded (quote) quick fix add derived's class body:

using a<derived>::foo;  using b<derived>::foo; 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -