は私がのstd ::関数の引数に「中継」されているテンプレートパラメータの可変数、とテンプレート機能を持っているパラメータしかし、Visual Studioは、このエラーメッセージが表示され、赤でメインにTEST1 -callsのすべてを強調:Visual Studioのエラーが
template<class... Args> void test1(const std::function<void(Args...)> &function)
no instance of function template "test1" matches the argument list
argument types are: (lambda []void(float f)->void)
この一方、エラーとして表示されません。
template<typename... Args>
void test2(Args... a)
{}
int main(int argc,char *argv[])
{
test2<float>(1.f);
return EXIT_SUCCESS;
}
は、私が最初のケースのために、誤って何かをやっているか、これは偽陽性のですか?これはビジュアルスタジオ自体からの単なるエラーですが、コンパイラは警告をスローしません。
//編集:
私はちょうどG ++でLinux上でいくつかのテストをした - 5、そしてそれは私がすべてのコードをコンパイルできません:
は[email protected]******:/var/projects# g++-5 -std=c++1y test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:12:22: error: no matching function for call to ‘test1(std::nullptr_t)’
test1<float>(nullptr);
^
test.cpp:5:7: note: candidate: template<class ... Args> void test1(const std::function<void(Args ...)>&)
void test1(const std::function<void(Args...)> &function)
^
test.cpp:5:7: note: template argument deduction/substitution failed:
test.cpp:12:22: note: mismatched types ‘const std::function<void(Args ...)>’ and ‘std::nullptr_t’
test1<float>(nullptr);
^
test.cpp:13:17: error: no matching function for call to ‘test1(void (*)(float))’
test1<float>(&t);
^
test.cpp:5:7: note: candidate: template<class ... Args> void test1(const std::function<void(Args ...)>&)
void test1(const std::function<void(Args...)> &function)
^
test.cpp:5:7: note: template argument deduction/substitution failed:
test.cpp:13:17: note: mismatched types ‘const std::function<void(Args ...)>’ and ‘void (*)(float)’
test1<float>(&t);
^
test.cpp:16:3: error: no matching function for call to ‘test1(main(int, char**)::<lambda(float)>)’
});
^
test.cpp:5:7: note: candidate: template<class ... Args> void test1(const std::function<void(Args ...)>&)
void test1(const std::function<void(Args...)> &function)
^
test.cpp:5:7: note: template argument deduction/substitution failed:
test.cpp:16:3: note: ‘main(int, char**)::<lambda(float)>’ is not derived from ‘const std::function<void(Args ...)>’
});
^
ビジュアルスタジオに限らず(自分の編集を参照) – Silverlan