[英]Template Inside Template Class
I have a class that looks like this: 我有一堂课,看起来像这样:
template <typename P>
class Pack {
Public:
template <typename X>
Private:
Other T <other>
};
I want to write the function outside of the class but I am having difficulties defining the header.. I tried something like this: 我想在类之外编写函数,但是在定义标题时遇到了困难。
template <typename X>
int Pack<X>::pop(X led) const{
// Do something in here with Other from the private above
}
But this does not work it keeps saying "Out of line definition of pop, does not match any definitions of P. 但这总是行不通,它一直说“ pop的脱机定义与P的任何定义都不匹配。
Any help is appreciated thanks! 任何帮助表示赞赏,谢谢!
Clarification: Trying to Implement the function stub so I can write the code outside of the class. 澄清:尝试实现功能存根,以便我可以在类之外编写代码。
Your code looks incomplete and you're posting small chunks of it from time to time but I believe this syntax is what you want: 您的代码看起来不完整,并且会不时发布其中的小块代码,但是我相信您想要的是这种语法:
#include <iostream>
using namespace std;
template <typename P>
class Stack {
public:
template <typename X> int pop(X pred) const;
};
template <typename P>
template<typename X>
int Stack<P>::pop(X pred) const{
return 0;
}
int main() {
Stack<bool> obj;
char a;
obj.pop(a);
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.