矢量模板参数无效

Vector template argument invalid

本文关键字:参数 无效      更新时间:2023-10-16

我有以下代码,

typedef struct node
{
   int data;
   node * left;
   node * right;
}node;
#include <vector>
std::vector<node*> findValue(node * node, int value, std::vector<node*> parents) {...}

但是我收到编译错误:

错误:模板参数 1 无效

 std::vector<node*> findValue(node * node, int value, std::vector<node*> parents) {
                                                                   ^

如何正确声明节点指针向量的函数参数?

in

std::vector<node*> findValue(node * node, int value, std::vector<node*> parents)

node * node将标识符node重新定义为变量。当编译器解析std::vector<node*> parents时,节点不再是可以在模板扩展中使用的类型。

溶液

重复使用名称时要小心。

std::vector<node*> findValue(node * notnode, int value, std::vector<node*> parents)

notnode是解决问题的一个例子。强烈建议使用更具描述性的名称。