다음 스 니펫에서 간단히 노출되는 사용자 정의 ostream 클래스를 생성합니다. std::endl
을 사용할 수 있기를 원하지만 컴파일러가 나를 허용하지 않습니다. 나는 왜 그런지 이해하지 못한다.사용자 정의 std :: ostream 클래스에서 std :: endl을 사용하는 방법
main.cpp:21:21: error: no match for ‘operator<<’ in ‘operator<< ((* & f), (*"aa")) << std::endl’ main.cpp:21:21: note: candidates are: main.cpp:13:9: note: template Foo& operator<<(Foo&, U&&) main.cpp:13:9: note: template argument deduction/substitution failed: main.cpp:21:21: note:
couldn't deduce template parameter ‘U’
이 왜 매개 변수를 U를 추론 할 수 없습니다
#include <iostream>
struct Bar
{
};
template <typename T>
struct Foo
{
};
template <typename T, typename U>
Foo<T>& operator<<(Foo<T>& _foo, U&&)
{
return _foo;
}
int main()
{
Foo<Bar> f;
f << "aa" << std::endl;
}
오류 GCC 4.7.1 날입니다 준다? 이것은 typeof(std::endl)
이 아니어야합니까? std::endl
이후
'typeof' 란 무엇입니까? – oldrinb
우리는'decltype'과'typeid'를 가지고 있습니다. – chris
@oldrinb java의 일부 연산자입니다. 나는'decltype '을 의미했다. – qdii