일부 코드가 있습니다.운영자 금지 << 전화
#include <iostream>
template<typename T>
struct Test
{
Test(bool v):flg(v) { }
void func() { }
typedef void (Test::*unspecified)();
operator unspecified() const
{
return flg ? &Test::func : 0;
}
bool flg;
};
template<typename T>
std::ostream& operator << (std::ostream&, typename Test<T>::unspecified);
int main()
{
Test<int> t(true);
std::cout << t << std::endl;
}
출력 그것은 잘 작동
1
입니다,하지만 난 정의되지 않은 참조를 얻을 싶어요. Test
이 not template class
이면 정의되지 않은 참조가 나타납니다. 그렇다면 컴파일러가 함수 유형으로 operator <<
을 사용하지 않고 pointer to class-member
에서으로 표준 변환을 수행하는 이유는 무엇입니까? 그것은 ::
의 왼쪽에 표시 이후
[템플릿 인수 공제가 여기서 작동하지 않는 이유는 무엇입니까?] (http://stackoverflow.com/questions/1268504/why-is-the-template-argument-deduction-not-working-here?lq=1)를 참조하십시오.) –
템플릿 std :: ostream & operator << (std :: ostream &, const Test &); 템플릿을 사용할 수없는 이유가 있습니까? –
juanchopanza