【问题标题】:error: conflicting declaration - cant a pointer be an int?错误:声明冲突 - 指针不能是 int 吗?
【发布时间】:2012-11-18 12:02:52
【问题描述】:

我正在尝试编译一个库,在运行make 时出现以下许多错误:

error: conflicting declaration ‘int x’
error: ‘x’ has a previous declaration as ‘Text* x’

代码如下:

.
.
.
class Text;
class Code {

    private:
            std::vector<std::string> *tokens;
            std::vector<std::string> *compounds;
            std::vector<std::string> *compound_xml;
            std::vector<std::string> *compound_xml_action;
            void set_helper(Text *x, int a, int b, int c, std::string field, std::string value);
            std::string itoa(int x);

    public:
            Code();
            ~Code();

            int analyse_code(Text *x, std::string c, int x, int y, int z);
            int print(Text *x, std::string c, int x, int y, int z);
            int is_class(Text *x, std::string c, int x, int y, int z);
            int is_class2(Text *x, std::string c, int x, int y, int z);
            int not_class(Text *x, std::string c, int x, int y, int z);

 .
 .
 .

所以在analyse_code 函数\方法中,我应该将int x 转换为int aint wtv 还是其他原因导致错误?

由于库的作者在许多函数中使用了Text* xint x,我想也许他知道他在做什么并且指针可以是int,或者我认为他知道他在做什么是错误的?

无关:库是Adso,中文文本分析引擎。

【问题讨论】:

  • 你错误地认为他知道自己在做什么。错误表明声明冲突,这是不对的。
  • 那我应该把int x改成int smth吧?
  • 嗯。库代码基本上充满了错误,而且通常很糟糕。作者似乎是在瞎写,没有检查它是否真的编译,而且他通常似乎不知道他实际上在做什么。不要使用它。
  • 我会将Text* x 更改为Text* text
  • 补充康拉德所说的。不仅有问题,而且是由对 C++ 了解有限的人编写的。

标签: c++ compiler-errors g++


【解决方案1】:

您在声明中有两个名为“x”的参数:

int not_class(Text *x, std::string c, int x, int y, int z);

将其中一个命名为其他名称。例如:

int not_class(Text *txt, std::string c, int x, int y, int z);

作者不是很好,请注意其他错误。

【讨论】:

  • 是的,他似乎喝醉了,因为我得到了error: ‘strcmp’ was not declared in this scope,因为他没有包含&lt;cstring&gt;...但是感谢您的回答...我会接受您的回答分钟,当我被允许...欢呼
【解决方案2】:

问题不仅在analyse_code 中,而且在所有私有函数中。如果你有源代码(.c 文件),我也会在那里查看。

无论如何,您应该将Text *x 更改为其他任何内容,例如Text *text

【讨论】:

  • 它也在源文件中。它显然遍及代码库。但这只是代码中的众多问题之一……
  • 如果代码写得这么糟糕,我可能想尝试寻找另一个库来使用。
猜你喜欢
  • 1970-01-01
  • 2021-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多