-1
foo
はstd::string
を返します。戻り値が変数に割り当てられていない場合、未解決の関数オーバーロード
auto s = foo(...) << std::endl;
std::cout << s << std::endl;
作品が、
std::cout << foo(...) << std::endl;
は、オペランドの型は「< 'のstd :: basic_ostrea <のchar>' であり、(
'演算子< <' の一致なしで失敗します未解決のオーバーロードされた関数タイプ> ')
エラーです。
全コード:
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
#include <type_traits>
// checks if It is an iterator type
template<typename It, typename Base = std::input_iterator_tag>
struct is_iterator : public std::is_base_of<Base, typename std::iterator_traits<It>::iterator_category> {};
// dummy function that takes in iterator
template<typename It, typename = typename std::enable_if_t<is_iterator<It>::value>>
std::string foo(It it) { return "foo it"; }
int main() {
std::vector<int> v{1};
// works
auto s = foo(v.begin());
std::cout << s << std::endl;
// doesn't
std::cout << (foo(v.begin())) << std::end;
}
なぜ失敗割り当てなしの呼び出し?私の推測では、私のテンプレート定義に何か問題がありますが、私はそれが何であるか把握できません。
'のstd :: coutの<<(FOO(v.begin()))<<はstd ::エンド;'非常に*その行を見てください*密接に、あなたがタイプミスを見つけることができるかどうかを見てください:) – Rakete1111
[** std :: end **は** std :: endl **!ではないので(http://coliru.stacked-crooked.com/a/f4d29506b9c47e0c) – user1810087