Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;“编译错误”;不为类型命名";使用上面定义的类型,错误发生在哪里?_C++ - Fatal编程技术网

C++ C++;“编译错误”;不为类型命名";使用上面定义的类型,错误发生在哪里?

C++ C++;“编译错误”;不为类型命名";使用上面定义的类型,错误发生在哪里?,c++,C++,我编写了一个包,在编译时遇到了“不命名类型”的问题 代码如下: 骷髅 #include "gp.h" ... class Formula : public GP { ... }; ... class FormulaPopulation : public GPPopulation { ... Formula* NthMyGP (int n) { return (Formula*) GPContainer::Nth

我编写了一个包,在编译时遇到了“不命名类型”的问题

代码如下: 骷髅

  #include "gp.h"

  ...       

  class Formula : public GP
  {
     ...
  };

  ...

  class FormulaPopulation : public GPPopulation
  {
     ...
     Formula* NthMyGP (int n) { return (Formula*) GPContainer::Nth (n); }
     ...
  };
当我编译时,编译器会指出公式(在FormulaPopulation中)没有命名类型,但类公式定义在类FormulaPopulation的正上方,我不知道为什么会发生此错误

如果您想了解更多信息,可以下载该软件包。 (下载后,卸载此文件并在“printNatural”目录下生成。您可以看到错误)


任何帮助都将不胜感激。

如果复制和粘贴的代码与项目中的代码相同,则缺少分号:

  #include "gp.h"
  class Formula : public GP
  {
     ...
  }; // <-- HERE

  ...

  class FormulaPopulation : public GPPopulation
  {
     ...
     Formula* NthMyGP (int n) { return (Formula*) GPContainer::Nth (n); }
     ...
  }; // <-- HERE
#包括“gp.h”
类别公式:公共GP
{
...

}; // 您的tarball无法生成,因为文件丢失,但有一个
extern向量公式这将导致冲突


显然,定义
公式
类而不引起冲突是可能的,而使用它是不可能的,这是非常令人困惑的

你能粘贴实际的代码片段吗?关闭类定义的括号后,您的帖子缺少分号,这很容易让编译器感到困惑。很抱歉,我犯了这个错误…这不是分号的问题。您的tarball无法生成,因为缺少文件,但是
extern vector Formula可能与您的问题有关。哦,不要使用名称空间std编写
在你的标题中,永远。发布演示问题的代码。总结不起作用。Thx molbdnilo,我通过更改
外部向量公式修复了原始问题
外部向量公式以避免“不命名类型”的问题。很抱歉犯了这个错误…这不是分号的问题。