我使用的cocos2d-x創建我的項目,但我得到這個錯誤:頭文件無法訪問
Error (active) "CocosDenshion::SimpleAudioEngine::SimpleAudioEngine()" (declared at line 256 of "c:\MyGame \cocos2d\cocos\audio\include\SimpleAudioEngine.h") is inaccessible MyGame c:\MyGame \Classes\MyGame .cpp
所以我包括SimpleAudioEngine.h文件到我的CPP文件,一起工作它。正如你可以從錯誤中看到,使用SimpleAudioEngine,我需要先用CocosDenshion命名空間,但只要我做打字:
CocosDenshion::SimpleAudioEngine()
的Visual Studio顯示這個錯誤對我來說,VS能告訴我該聲明告訴我它知道標題在哪裏,並且可以被讀取。所以我不知道無法訪問會有什麼問題。頭文件無法訪問的原因是什麼?
MyGame.cpp
#include "MyGame.h"
#include "SimpleAudioEngine.h"
#include "GlobalVariables.h"
USING_NS_CC;
Scene* MyGame::createScene()
{
auto scene = Scene::create();
auto layer = MyGame::create();
scene->addChild(layer);
return scene;
}
bool MyGame::init()
{
if (!Layer::init())
{
return false;
}
is_dragged = false;
const char* MUSIC_PATH = "Music/Main_Theme_loop.ogg";
initTouch();
initTiled();
tempSetupSprite();
debugDrawLine();
this->scheduleUpdate();
return true;
}
MyGame.h
#include "GameSprite.h"
#include "GameMap.h"
class MyGame : public cocos2d::Layer
{
private:
void update(float dt);
void initTouch();
void initTiled();
void tempSetupSprite();
void debugDrawLine();
public:
static cocos2d::Scene* createScene();
virtual bool init();
virtual bool onTouchBegan(cocos2d::Touch* _touch, cocos2d::Event* _event);
virtual void onTouchEnded(cocos2d::Touch* _touch, cocos2d::Event* _event);
virtual void onTouchMoved(cocos2d::Touch* _touch, cocos2d::Event* _event);
virtual void onTouchCancelled(cocos2d::Touch* _touch, cocos2d::Event* _event);
CREATE_FUNC(MyGame);
private:
bool is_dragged;
Vec2 first_touch;
Vec2 last_drag_touch;
GameSprite* sprite;
GameMap* map;
};
這意味着'SimpleAudioEngine'的默認構造函數是'private'或'protected'。 – vu1p3n0x
再次閱讀錯誤消息。它並沒有說頭文件是不可訪問的;它說構造函數'CocosDenshion :: SimpleAudioEngine :: SimpleAudioEngine()'是不可訪問的(可能它是私有的)。 – davmac