如何创建模板方法的别名
How to create alias to template method
从这个链接(1056)。模板别名、成员定义和当前实例化)我意识到,我们可以在模板中创建别名,例如,我们可以这样做
template<typename T>
using Vec = std::vector<int>
如何为模板方法创建别名,我在下面尝试过,但它抛出编译错误error: missing template arguments before '.' token
#include <iostream>
using namespace std;
template <class T> struct A
{
float g(T x){return(x*0.01);}
};
template <class T> using B = A<T>;
int main()
{
B.g<int>(10);
// your code goes here
return 0;
}
我不确定如何为模板方法创建别名,请有人阐明这一点
你的句子顺序有点不对,正确的应该是:
B<int>().g(10);
ie。你创建一个B<int>
对象并调用它的g
函数。
tmpl.cpp:13:5: error: use of class template 'B' requires template arguments
B.g<int>(10);
^
tmpl.cpp:9:20: note: template is declared here
template <class T> using B = A<T>;
~~~~~~~~~~~~~~~~~~ ^
tmpl.cpp:13:6: error: cannot use dot operator on a type
B.g<int>(10);
^
相关文章:
- 将成员函数指针作为参数传递给模板方法
- 模板方法访问正向声明的类仅在没有此指针的情况下无法编译
- C++11:模板方法的模板函数调用无法编译?
- 如何从ECS中的模板方法获取组件?
- 使用 SFINAE 设计模板方法
- 一个模板方法,用于同时接受常量和非常量参数
- C++模板方法中的循环依赖关系
- 在 C++ 中使用模板方法重写类方法
- 类中的模板方法
- 基于枚举参数调用专用模板方法
- C++ N 维向量的模板化别名
- 模板中的模板方法 - 实例声明和类方法声明签名不同
- 如何在容器中指定模板化别名的泛型类型
- 可变参数模板方法
- 使用模板方法为标头提供空 cpp 时出现问题
- SFINAE 方法在 clang 中完全禁用基类的模板方法
- 将函数和成员函数传递给模板方法
- 如何为静态模板方法设置别名
- 模板类模板方法参数中的模板别名不起作用
- 如何创建模板方法的别名