0

我有一个类,它为另一个类设置了一些变量,但我似乎无法让它工作,因为我得到一个错误。

所以我有这个:


MainMenu::MainMenu(std::map<std::string,std::string>& theme){ 
    CreateSprite Background(theme["Background"]);
}

void create(sf::RenderWindow& output){
    output.draw( Background.callback() );
}

它的标题:


class MainMenu
{
private:

CreateSprite Background;

public:
MainMenu(std::map<std::string, std::string>&);
void create(sf::RenderWindow&);

};

问题是我得到:

error C2512: 'CreateSprite' : no appropriate default constructor available

我的课程CreateSprite设置如下:


CreateSprite::CreateSprite(std::string& imagefile) {

if(!image.loadFromFile(imagefile)){
    exit(2);
}

sprite = sf::Sprite(image);
}

sf::Sprite CreateSprite::callback(){
return sprite;
}

这个类的相关header内容是:


class CreateSprite
{
public:

CreateSprite(std::string&);
sf::Sprite callback();

private:

sf::Texture image;
sf::Sprite  sprite;

};

我有什么不正确的?

4

1 回答 1

1

我猜你MainMenu已经声明了一个成员Background,你应该从成员初始化器中初始化它:从

MainMenu::MainMenu(std::map<std::string,std::string>& theme){ 
    CreateSprite Background(theme["Background"]);
}

MainMenu::MainMenu(std::map<std::string,std::string>& theme)
:Background(theme["Background"])
{     
}
于 2012-11-13T03:03:04.510 回答