C++ cocos2dx中的覆盖函数

C++ cocos2dx中的覆盖函数,c++,svg,cocos2d-x,C++,Svg,Cocos2d X,我正在创建基于关卡的游戏。SVG文件在不同层次上难以覆盖 这是代码 HelloWorld.cpp const char* HelloWorld::SVGFileName() //virtual function { return NULL; } CCScene* HelloWorld::scene() { CCScene *scene = CCScene::create(); HelloWorld *game = HelloWorld::create();

我正在创建基于关卡的游戏。SVG文件在不同层次上难以覆盖

这是代码

HelloWorld.cpp

 const char* HelloWorld::SVGFileName()     //virtual function
 {
   return NULL;
 }

CCScene* HelloWorld::scene()
{
   CCScene *scene =  CCScene::create();
   HelloWorld *game = HelloWorld::create();
   GameHUD *hud = GameHUD::HUDWithGameNode(game);
   game->hud_ = hud;
   scene->addChild(game);
   scene->addChild(hud, 10);
   return scene;
 }
1.h级

 class CC_DLL level1: public HelloWorld
 {
 public:
   level1();
   ~level1();
    const char* SVGFileName();
    void addBodyNode(BodyNode* node,int zOrder);
    void initGraphics();
 };
级别1.cpp

 const char* level1::SVGFileName()
 {
    CCLog("LevelSVG: level: override me");
    return ("test3.svg");
 }
选择levelscene.cpp

void SelectLevelScene::level0()
{
   CCDirector::sharedDirector()->replaceScene(level1::scene());
}
我的问题是

我无法重写level1.cpp中的函数SVGFileName()。我的代码有问题吗


有没有办法修复它?

返回在函数的本地作用域中创建的常量字符*。这意味着一旦函数返回,返回的指针就是垃圾


您应该返回std::string。

不能返回是什么意思?编译器抛出错误或未调用函数?@wezsieto:编译器抛出的是“CCAssert(pszRelativePath!=NULL,“CCFileUtils:Invalid path”);”。函数没有调用。#LearnCos2D:我有问题。我忘了在水平面设置HUD层。它很好用。level1*layer=level1::create();GameHUD*hud=GameHUD::HUDWithGameNode(层);图层->抬头显示器(hud)=hud;还有std::string level1::SVGFileName(){CCLog(“LevelSVG:level:override me”);返回“test3.svg”;}