当我尝试声明类“Game”的实例时,我收到 main.cpp 的编译错误“错误:“游戏”未命名类型”。
如果可能并不重要,但我正在使用代码块。
Game.cpp中的相关代码
#include "../include/main.h"
class Game
{
private:
public:
};
Main.cpp中的相关代码
#include "../include/main.h"
Game g; //this is the line it is referring to
int main(int argc, char* args[])
{
return 0;
}
我才开始学习 C++ 所以我可能忽略了一些明显的:(
在标题中包含“游戏”声明
记事本main.h =>
#ifndef MAIN_H
#define MAIN_H
class Game
{
private:
...
public:
...
};
#endif
// main.h
记事本main.cpp =>
#include "main.h"
Game g; // We should be OK now :)
int
main(int argc, char* args[])
{
return 0;
}
gcc -g -Wall -pedantic -I../include -o main main.cpp
注意你如何:
1)在标头中定义您的类(以及任何类型定义、常量等)
2) #include 任何需要这些定义的 .cpp 文件中的标头
3) 使用“-I”编译以指定包含标头的目录(或多个目录)
'希望有帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)