C++ 未知类型名称类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16336244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unknown type name class
提问by Sebastian Otto
I have the following header files:
我有以下头文件:
https://gist.github.com/wemakeweb/5501443and the compiler always reports "Unknown Type name Class". I have included Forward Declaration, to break circular including , where i think i have to. What did i forget?
https://gist.github.com/wemakeweb/5501443并且编译器总是报告"Unknown Type name Class"。我已经包括了前向声明,以打破循环,包括,我认为我必须这样做。我忘记了什么?
Edit: i put it all in one header file, and the compiler still reports "expected ; after top level declarator"
编辑:我把它全部放在一个头文件中,编译器仍然报告“预期;在顶级声明符之后”
https://gist.github.com/wemakeweb/5583500
https://gist.github.com/wemakeweb/5583500
Edit 2Now im getting linker errors. "Undefined symbols for architecture x86_64"
编辑 2现在我收到链接器错误。“体系结构 x86_64 的未定义符号”
Solved, Problems were
已解决,问题是
- Circular Including
- main.c instead of main.cpp
- the actual code was in a static lib which was not linked properly
- 圆形包括
- main.c 而不是 main.cpp
- 实际代码位于未正确链接的静态库中
回答by Roddy
This error? error: unknown type name ‘class'
这个错误? error: unknown type name ‘class'
You're probably compiling it as C rather than C++.
您可能将其编译为 C 而不是 C++。
Make sure your source file has a .cpp
extension, and than any relevant compiler flags are set correctly. (It helps if you include the exacterror message and line numbers. Don't try and retype, just cut+paste.)
确保您的源文件具有.cpp
扩展名,并且正确设置了任何相关的编译器标志。(如果您包含确切的错误消息和行号,这会有所帮助。不要尝试重新键入,只需剪切+粘贴即可。)
回答by juanchopanza
You have at least one cyclic include dependency between Feld.h
and Figur.h
. The forward declarations have no effect if you also include the headers. Just remove the includes.
您在Feld.h
和之间至少有一个循环包含依赖项Figur.h
。如果您还包含标题,则前向声明无效。只需删除包含。