Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[3.138.35.114] |
|
Сообщ.
#1
,
|
|
|
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 |
Сообщ.
#2
,
|
|
|
Цитата Koss @ почему ошыпки? Ты объявляешь оператор как функцию-член. В этом случае надо писать только один аргумент у оператора (правый операнд, а this будет левым операндом), либо же делать статический оператор. |
Сообщ.
#3
,
|
|
|
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; } |
Сообщ.
#4
,
|
|
|
Цитата Koss @ а как правильней писать? Практически, без разницы. Дело вкуса. |
Сообщ.
#5
,
|
|
|
Цитата Koss @ bool operator == (const cilindr<T> &a2) { if(*this.radius == a2.radius) return true; else return false; } Эх... bool operator == (const cylinder &a) const { return radius == a.radius; } |
Сообщ.
#6
,
|
|
|
а ведь в начальном коде надо было изменить всего одно слово
friend bool operator == (const cilindr<T> &a1 ,const cilindr<T> &a2) { if(a1.radius == a2.radius) return true; else return false; } |
Сообщ.
#7
,
|
|
|
template <typename T> const bool operator == (const cilindr<T> &a1 ,const cilindr<T> &a2) { if(a1.radius == a2.radius) return true; else return false; } по-моему, так |