C++ 不带<;的模板方法实现&燃气轮机;
我在课堂上有一个模板方法:C++ 不带<;的模板方法实现&燃气轮机;,c++,templates,gcc,c++03,C++,Templates,Gcc,C++03,我在课堂上有一个模板方法: template<class T> A& doSomething(T value) 带模板的最后5行的确切含义是什么 谢谢这行代码没有实现。对于类型char const*,char,int,int*,int*和double template A& A::doSomething(char const*); template A& A::doSomething(char); template A& A::doSomet
template<class T>
A& doSomething(T value)
带模板的最后5行的确切含义是什么
谢谢这行代码没有实现。对于类型
char const*
,char
,int
,int*
,int*
和double
template A& A::doSomething(char const*);
template A& A::doSomething(char);
template A& A::doSomething(int);
template A& A::doSomething(int*);
template A& A::doSomething(double);
它是,强制使用指定的模板参数实例化模板,并防止其隐式实例化
显式实例化定义强制对
它们所指的函数或成员函数。它可能出现在
在模板定义之后的任意位置,针对给定的
参数列表,只允许在程序中出现一次
显式实例化声明(外部模板)防止
隐式实例化:否则会导致
隐式实例化必须使用显式实例化
程序中其他地方提供的定义
看看
<>因为您标记了C++ 03,请注意,链接页面中提到的
template<>
A& A::doSomething(bool value){
// do something special with value of type bool
return *this
}
template A& A::doSomething(char const*);
template A& A::doSomething(char);
template A& A::doSomething(int);
template A& A::doSomething(int*);
template A& A::doSomething(double);
...
template A& A::doSomething(char const*);
template A& A::doSomething(char);
template A& A::doSomething(int);
template A& A::doSomething(int*);
template A& A::doSomething(double);