Why can't I call a templated method from a derived class instance in C++?

The problem you are facing is called hiding. Basically the lookup rules in the language will start in the most derived type and work their way back up until it finds the appropriate symbol. In your case it will stop while looking at the B class as it finds void B::foo(const std::string& name) At that level, the only potential overload that it will consider is the one it is seeing.

The problem you are facing is called hiding. Basically the lookup rules in the language will start in the most derived type and work their way back up until it finds the appropriate symbol. In your case it will stop while looking at the B class as it finds void B::foo(const std::string& name).

At that level, the only potential overload that it will consider is the one it is seeing. To avoid hiding you can bring all the other overloads you can add a using declaration: struct B : A{ using A::foo; void foo( const std::string & name ); }; The difference is that lookup will work up the hierarchy until it finds the first overload, which is again at B level, but because of the using directive, it will also consider any overload available in A. Alternatively, you can leave the symbol hidden and force dispatch to the exact class by qualifying the call (note that this has the side effect of disabling dynamic dispatch, which is not a problem here, but could be if the overload to use is virtual): b->A::foo().

Because of my A::foo(const std::string&) being pure virtual I was assuming the templated version of foo was not hidden in B... Anyhoo, thanks David. – mister why May 17 at 13:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions