我正在创建一个数据结构,但是当我尝试编译时,我收到一条错误消息,指出我没有指定我正在初始化的集合类型。
我正在使用用于大量数据的 NTL 库。
这是我的代码:
#include <set>
#include ...
NTL_CLIENT
using namespace std;
using namespace NTL;
const RR ZERO = to_RR(0);
const RR ONE = to_RR(1);
const RR TWO = to_RR(2);
class tenTree
{
public:
tenTree(string newName = "", int newLevel = 0);
~tenTree();
void put(string prefix, RR power);
bool get(string prefix, RR & output);
void display(int depth);
bool isKnown(RR power){return (powers.find(power) != powers.end());};
private:
tenTree* children [10];
set<int> powers;
int level;
string name;
bool child[10];
};
当我尝试编译时返回错误信息:
twoPow.cpp:47: error: ISO C++ forbids declaration of \u2018set\u2019 with no type
twoPow.cpp:47: error: expected \u2018;\u2019 before \u2018<\u2019 token
twoPow.cpp: In member function \u2018bool tenTree::isKnown(NTL::RR)\u2019:
twoPow.cpp:44: error: \u2018powers\u2019 was not declared in this scope
我在这里遗漏了什么吗?
最佳答案
这只是范围的问题。我所要做的就是在 set 之前添加一个 std::并且它可以正确编译。
关于c++ Set无法正确编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17711936/