【问题标题】:c++ Set not compiling properlyc++ Set 编译不正确
【发布时间】:2013-07-18 07:28:14
【问题描述】:

我正在创建一个数据结构,但是当我尝试编译时,我收到一条错误消息,提示我没有指定我正在初始化的集合类型。

我正在使用用于大数字的 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:错误:ISO C++ 禁止声明没有类型的 \u2018set\u2019
twoPow.cpp:47: 错误:预期 \u2018;\u2019 之前 \u2018 twoPow.cpp: 在成员函数\u2018bool tenTree::isKnown(NTL::RR)\u2019:
twoPow.cpp:44:错误:\u2018powers\u2019 未在此范围内声明

这里有什么我遗漏的吗?

【问题讨论】:

  • 我认为这是一个头文件。请从不在头文件中执行using namespace ...;
  • 是的,在那儿打一个 std::...
  • 不幸的是,我的学校让我们将所有代码放在一个文件中。这不是标题。
  • bool isKnown(RR power)的定义后面多了一个;,不确定是否重要...
  • @SSAdmin 他的意思是不要使用“using”,而是使用 std::string 和 NTL::RR 等命名空间来限定每种类型。使用命名空间 std 删除行;使用命名空间 NTL;

标签: c++ compiler-errors set ntl


【解决方案1】:

这只是范围的问题。我所要做的就是在集合之前添加一个 std:: 并正确编译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-30
    • 2012-11-10
    • 1970-01-01
    • 2013-02-08
    • 2013-08-24
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    相关资源
    最近更新 更多