Re: name resolution of inherited templated classes?

  • From: Dave <davidct1209@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Wed, 28 Jul 2010 21:59:23 -0700

It's hard to say without looking at the source, but according to the
link I gave (as I've never run into this particular dark corner
before), when you have classes that inherit from templated classes,
the compiler performs name lookup's in the base class only on
dependent methods/members.  So, in your case, Get() isn't a dependent
method since it has no template parameters.
Dependent names are ones that take a template.  Refer to the link I
gave for a better explaination.

Have you tried defining a method GetPlayerAttribute(...) in player
that simply did the following?
void Player::GetPlayerAttribute(std::string attribute) {
this->Get(attribute);  // resolves correctly to base Get()

On 7/28/10, Tyler Littlefield <tyler@xxxxxxxxxxxxx> wrote:
> hello,
> I've played around with this some again today, and still having the same
> issues. I moved VariableContainer up to Entity, but it doesn't seem as if
> the template is being resolved before, so it's causing a problem. Is there a
> workaround?
>               Thanks,
> Tyler Littlefield
>       Twitter: sorressean
> On Jul 28, 2010, at 7:33 AM, Dave wrote:
>> I'll take a crack at this one.  Are your subclasses taking class
>> templates as well?  If so, then take a look at 35.19 of:
>> Not sure what context you're calling Get() from, but likely the second
>> or third workaround they mentioned could help.
>> On 7/27/10, Tyler Littlefield <tyler@xxxxxxxxxxxxx> wrote:
>>> Hello all,
>>> I'm working on my game engine again, and ran into a bit of a problem.
>>> I have a function that is called when a command is ran, which gets passed
>>> a
>>> pointer to the player that called it.
>>> What I'm trying to do is get a variable from my VariableContainer class,
>>> which finds the variant and returns the value. So, basically:
>>> Player inherits Entity (which is a game object), and Entity inherits the
>>> templated VariableContainer class.
>>> In my command I have something like:
>>> int str=mobile->Get("strength");
>>> When I compile, it says that the get function could not be found in class
>>> 'Player'.
>>> Is there a workaround to this? I tried adding a Get function into Entity
>>> which would do:
>>> VariableContainer::Get("bla") and return that, but that failed also.
>>>             Thanks,
>>> Tyler Littlefield
>>>     Twitter: sorressean
>>> __________
>>> View the list's information and change your settings at
>> __________
>> View the list's information and change your settings at
> __________
> View the list's information and change your settings at
View the list's information and change your settings at

Other related posts: