【发布时间】:2020-07-01 16:02:13
【问题描述】:
#include <iostream>
#include <string>
#include <map>
using namespace std;
template<typename T>
struct Node
{
map<string, T> data;
struct Node* left, * right, * bottom;
Node(map<string, T> data)
{
this->data = data;
left = right = bottom = NULL;
}
};
int main()
{
cout << endl;
map <string, string> test;
test["walid"] = "walid";
struct Node* root = new Node(test); #error here
cout << root->data["walid"];
cout << endl;
return 0;
}
谁能告诉我为什么我收到不完整的类型错误?我正在尝试根据数据使用不同的地图值类型创建节点。
【问题讨论】:
-
Node是模板类型,您没有指定模板参数。 -
你应该edit你的帖子引用完整的错误,请。
-
研究推导指南,看看如何避免指定类型参数并让它从构造函数调用中推导出来。
标签: c++ dictionary templates struct