#include
#include
using namespace std;
template class Test;
template
bool operator==(const Test &, const Test &);
template
class Test {
friend bool operator==(const Test &, const Test &);
private:
int data;
};
template
bool operator==(const Test &lhs, const Test &rhs)
{
return lhs->data == rhs->data; // clause 1. This seems to compile even though lhs/rhs is not a pointer. The arrow operator would be something like (*lhs).data. But in this case lhs/rhs is a reference.
}
int main()
{
return 0;
}
< /code>
< /li>
Без шаблона - компилируется с выпуском < /p>
#include
#include
using namespace std;
class Test {
friend bool operator==(const Test&, const Test&);
public:
int data;
};
bool operator==(const Test&lhs, const Test&rhs)
{
return lhs->data == rhs->data; // clause 2. Now this fail which is expected.
//return lhs.data == rhs.data; // clause 3. This would work as expected.
}
int main()
{
return 0;
}
Похоже, что пункт 1 противоречит значению использования оператора стрелки в качестве LHS/RHS не является указателем, но еще он составил. Это должно было терпеть неудачу, но это не так. Какая -либо причина такого поведения?
У меня есть примеры примеров: < /p> [list] [*] Использование Template - Compiles без выпуска < /p> [code]#include #include using namespace std;
template class Test; template bool operator==(const Test &, const Test &);
template class Test { friend bool operator==(const Test &, const Test &); private: int data; };
template bool operator==(const Test &lhs, const Test &rhs) { return lhs->data == rhs->data; // clause 1. This seems to compile even though lhs/rhs is not a pointer. The arrow operator would be something like (*lhs).data. But in this case lhs/rhs is a reference. }
int main() { return 0; } < /code> < /li> Без шаблона - компилируется с выпуском < /p> #include #include using namespace std;
class Test { friend bool operator==(const Test&, const Test&); public: int data; };
bool operator==(const Test&lhs, const Test&rhs) { return lhs->data == rhs->data; // clause 2. Now this fail which is expected. //return lhs.data == rhs.data; // clause 3. This would work as expected. }
int main() { return 0; } [/code]
[/list] Похоже, что пункт 1 противоречит значению использования оператора стрелки в качестве LHS/RHS не является указателем, но еще он составил. Это должно было терпеть неудачу, но это не так. Какая -либо причина такого поведения?