【发布时间】:2019-02-25 05:33:50
【问题描述】:
我正在尝试实现嵌套类中的方法,即模板内的方法,但是我无法做到这一点。我是 cpp 的新手,想知道我是否可以按照我在这里编码的方式来实现它,比如在命名空间和类范围之外。
namespace structures {
template<typename T>
class a {
public:
int funca();
int funcb();
private:
class b {
void funcc();
}
}
template<typename T>
int a<T>::funca() {
// method implementation
}
template<typename T>
int a<T>::funcb() {
// method implementation
}
// HOW DO i IMPLEMENT THE class b METHODS HERE??
template<typename T>
void a<T>::b<T>::funcc(){
//Didn't work
}
};
【问题讨论】:
-
函数需要返回类型。
-
a<T>::b不是模板。它不需要模板参数。
标签: c++ class templates nested