вторник, 18 октября 2011 г.

error: there are no arguments to '' that depend on a template parameter, so a declaration of '' must be available

Когда получаешь error: there are no arguments to 'XXX' that depend on a template parameter, so a declaration of 'XXX' must be available. Это значит в шаблонном классе была вызвана не шаблонная функция.
Решение - явно указать Класс::XXX или включить функцию в namespace
Подробнее(отсюда):



There are no arguments to 'X' that depend on a template parameter, so a declaration of 'X' must be available
Aside: I have a C++ prograof moderate complexity that I have to return to every 12-18 months to fix an obscure bug or add a modest festure.And every time, I spent one or two days just trying to get the thing build with the latest compiler, which picks up previously legal code and decides to whine about it, generating dozens of errors.
This is not the fault of the compiler. This is the fault of C++ for being so sloppy and complex. This is why C++ should just die and give watoJava.

The Error

Compiling a templated class that "worked previously" (under gcc3.3. as opposed to 4.x), an error was thrown on a previously acceptable andnon-templated member:
/Users/agapow/Desktop/mloc/ComboMill.h:188: error: there are no arguments to 'SetMemberShip'
that depend on a template parameter, so a declaration of 'SetMemberShip' must be available
Huh. A simplfied version of the class looks like this:
template  class ComboMill
{
 // ...
 
 void SetMembership (bool iIsMember)
 {
  for (int i = 0; i < mMembership.size(); i++)
  {
   mMembership[i] = iIsMember;
  }
 }
 
 void First ()
 {
  // error on next line
  SetMembership (false);
 }

 // ...
};
SetMembership is called by a numbeof other methods to toggle the state of set members. But that isn't the problem - the problem occurs where other methods go to call SetMembership.

Solution

It'a tough error to google for, but basically C++ is being stricter about how it identifies what you are calling. Where previously a symbol "X" would be implicitly taken to refer to a member or method "X" on the parent class, here C++ is insisting that you make it explicit. Thus it can easily be fixed by writing:
void First ()
 {
  // error on next line
  this->SetMembership (false);
 }

 // ...
};
Onof the criticisms made about Python is that you have to explicitly membeaccess qualify with "self". It seems C++ is also not longer immune form this.

2 комментария:

  1. Долго тупил, пока сюда не забрел, спасибо большое, помогло))

    ОтветитьУдалить
    Ответы
    1. Я и сам неплохо тупил, пока не накопал причину, ошибка не слишком распространена =)
      Рад, что смог вам помочь =)

      Удалить