实例化函数模板时出错
Error instantiating function template
我正在尝试下面简单的事情来练习ADL的行为
namespace test{
struct S{ public: s():a(10){} int a;};
template<typename T>
void fun(S o){
T a{};
std::cout<<(a+o.a)<<"n";
}
}
int main(){
test::S A;
fun<int>(A);
}
error1: expected primary-expression before ‘int’
fun<(int)>(A);
error2:'fun’ was not declared in this scope
fun<int>(A);
我不确定第一个错误(有任何东西来处理c++令人烦恼的解析吗?)和第二个错误,因为我已经通过了S
类型的参数,我相信ADL会考虑S
及其相关的namespace test
,但不确定为什么我得到'fun’ was not declared
错误。
您在test-namespace中放置了fun<>
用test::fun
相关文章:
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 将重载的成员函数传递给函数模板
- C++17中函数模板中的静态数组初始化(MSVC 2019)
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- 具有常量引用参数的函数模板专用化
- std::span<const T> 作为函数模板中的参数
- 如何编写一个完美的缩写函数模板?
- 仅在函数模板中为那些定义了函数的类型执行函数
- 如何在C++中伪造虚拟可变参数函数模板?
- 以下代码中的函数模板有什么问题?
- 类和成员函数模板专用化出错
- 尝试将 C++11 代码转换为 C++03 时默认函数模板参数出错
- 'Incomplete type' 为标准::函数声明指向成员的指针函数模板参数时出错
- 推导变差函数模板时出错
- 定义指向函数模板实例的std::函数指针时出错,该实例是模板化类的成员
- 解析公用派生基类模板中的函数模板名称时出错"Not declared in this scope"
- 实例化函数模板时出错
- 在vc++中将变量声明为' extern char[] '传递给函数模板时出错
- 调用函数模板时出错"No matching function"
- 用C++编译函数模板时出错