[英]Passing templated class?
I'm working on performing some operations on a polymorphic doubly-linked list, and I seem to be having some issues with that. 我正在对多态双链表执行一些操作,但似乎有一些问题。
I'm trying to pass a instance of the class to this function: 我试图将类的实例传递给此函数:
void performoperator(List<string> list, string operator, int &OpCount){
//...
}
and I'm trying to call it as such: 我试图这样称呼它:
List<string> list;
//...
performoperator(list, temp, OpCount);
The compiler doesn't appear to accept the way in which I'm calling the function, and I'm fairly certain the issue is with the templated class somehow. 编译器似乎不接受我调用该函数的方式,并且我可以肯定地确定问题在于模板类。 What am I doing improperly?
我在做什么不当?
Edit : Resolved, won't let me post as a solution as I'm a new user. 编辑 :已解决,因为我是新用户,所以不让我发布解决方案。 The issue was the I needed to pass the list by reference.
问题是我需要通过引用传递列表。
void performoperator(List<string> list, string operator, int &OpCount)
^^^^^^^^
operator
is a reserved keyword in C++; operator
是C ++中的保留关键字; you cannot use it as a variable name. 您不能将其用作变量名。
只是一个猜测:您将模板代码放在cpp文件中而不是在头文件中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.