На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Модераторы: Qraizer, Hsilgos
  
> Опять шаблоны классов
    ExpandedWrap disabled
          const bool operator == (const cilindr<T> &a1 ,const cilindr<T> &a2)
           {
              if(a1.radius == a2.radius)
              return true;
              else return false;
           }

    почему ошыпки?
    Цитата
    error C2804: binary 'operator ==' has too many parameters
    see reference to class template instantiation 'cilindr<T>' being compiled
    error C2333: '==' : error in function declaration; skipping function body
    see reference to class template instantiation 'cilindr<T>' being compiled
    error C2804: binary 'operator ==' has too many parameters
    see reference to class template instantiation 'cilindr<float>' being compiled
    error C2333: '==' : error in function declaration; skipping function body
    see reference to class template instantiation 'cilindr<float>' being compiled
      Цитата Koss @
      почему ошыпки?

      Ты объявляешь оператор как функцию-член. В этом случае надо писать только один аргумент у оператора (правый операнд, а this будет левым операндом), либо же делать статический оператор.
        ExpandedWrap disabled
              
          bool operator == (const cilindr<T> &a2)
               {
                  if(*this.radius == a2.radius)
                  return true;
                  else return false;
               }

        переделал-работае

        Добавлено
        а как правильней писать? как было выше, или без использования *тхис ?
        bool operator == (const cilindr<T> &a2)
        {
        if(radius == a2.radius)
        return true;
        else return false;
        }
          Цитата Koss @
          а как правильней писать?

          Практически, без разницы. Дело вкуса.
            Цитата Koss @
            bool operator == (const cilindr<T> &a2)
            {
            if(*this.radius == a2.radius)
            return true;
            else return false;
            }

            Эх... :(

            ExpandedWrap disabled
              bool operator == (const cylinder &a) const
              {
                  return radius == a.radius;
              }
              а ведь в начальном коде надо было изменить всего одно слово ;)
              ExpandedWrap disabled
                    friend bool operator == (const cilindr<T> &a1 ,const cilindr<T> &a2)
                     {
                        if(a1.radius == a2.radius)
                        return true;
                        else return false;
                     }
                ExpandedWrap disabled
                  template <typename T>
                   const bool operator == (const cilindr<T> &a1 ,const cilindr<T> &a2)
                       {
                          if(a1.radius == a2.radius)
                          return true;
                          else return false;
                       }

                по-моему, так ;)
                0 пользователей читают эту тему (0 гостей и 0 скрытых пользователей)
                0 пользователей:


                Рейтинг@Mail.ru
                [ Script execution time: 0,0262 ]   [ 16 queries used ]   [ Generated: 3.02.25, 08:10 GMT ]