我正在努力g++
汇编c++.11
这是我面临的问题:
error: 'IGameController' does not name a type.
IGameController
实际上是我的class
界面,我将该位置放在g++
脚本上。
这是我编译的g++
脚本:
cd C:\MinGW\bin\
g++ -std=c++11 -c c:\Users\me\Downloads\TheGame\TheGame.cpp
g++ -std=c++11 -Ic:\Users\me\Downloads\TheGame\GameController\inc -Ic:\Users\me\Downloads\TheGame\GameController\src -c c:\Users\me\Downloads\TheGame\GameController\src\GameController.cpp
g++ -std=c++11 -o c:\Users\me\Downloads\TheGame\TheGame.exe *.o
我不明白为什么脚本找不到我的头文件......
我的项目结构如下:
TheGame\TheGame.cpp
TheGame\GameController\inc\GameControllerProvider.hpp
TheGame\GameController\inc\IGameController.hpp
TheGame\GameController\src\GameController.cpp
TheGame\GameController\src\GameController.hpp
这是我的源代码:
[TheGame.cpp]
#include <iostream>
#include "GameController/inc/GameControllerProvider.hpp"
#include "GameController/inc/IGameController.hpp"
int main()
{
GameController::IGameController& gameController = GameController::GameControllerProvider::getGameController();
gameController.printSomething();
return 0;
}
[IGameController.hpp]
#pragma once
namespace GameController
{
class IGameController
{
public:
virtual void printSomething() = 0;
protected:
IGameController() {}
virtual ~IGameController() {}
};
}
[GameControllerProvider.hpp]
#pragma once
namespace GameController { class IGameController; }
namespace GameController
{
namespace GameControllerProvider
{
IGameController& getGameController();
}
}
[GameController.hpp]
#pragma once
#include "GameController/inc/IGameController.hpp"
namespace GameController
{
class GameController : public IGameController
{
public:
GameController();
virtual ~GameController();
void printSomething() override;
private:
};
}
[GameController.cpp]
#include <iostream>
#include "GameController/inc/IGameController.hpp"
#include "GameController/src/GameController.hpp"
#include "GameController/inc/GameControllerProvider.hpp"
namespace GameController
{
GameController::GameController() {}
GameController::~GameController(){}
void GameController::printSomething()
{
std::cout << "printSomething()" << std::endl;
}
}
// Provider
IGameController& GameControllerProvider::getGameController()
{
static GameController sGameController;
return sGameController;
}
}
答案 0 :(得分:1)
我不熟悉命名空间,但是肯定你的一个问题是#include
语句,你给某些文件提供了错误的路径。
例如,当你从IGameController.hpp
(在src /中)调用GameController.cpp
(在inc /中)时,由于你使用的是quoations marks(" "
),你应该给出完整的该文件的路径,应写为:
#include "../inc/IGameController.hpp"
希望它有所帮助。