我正在尝试返回 SDL Mix_Music 数据类型,但遇到问题
我知道我可以将所有 Mix_Musics 公开,而不用担心问题,但我仍然想了解如何做到这一点。
//header.h
class Music
{
private:
Mix_Music * BGMusic, * fall, * reset, * teleport, * win, * singleCubeWin;
public:
Music();
bool loadMusic();
void clean_up();
Mix_Music * getSound( Mix_Music * m ) { return m; }
};
//program.cpp
Music Sound;
int main( int argc, char* args[] )
{
...
Mix_PlayMusic( Sound.getSound( "BGMusic" ), -1 );
...
}
I know I could just make all the Mix_Musics public, and not worry about the problem, but I'd still like to understand how to do it.
//header.h
class Music
{
private:
Mix_Music * BGMusic, * fall, * reset, * teleport, * win, * singleCubeWin;
public:
Music();
bool loadMusic();
void clean_up();
Mix_Music * getSound( Mix_Music * m ) { return m; }
};
//program.cpp
Music Sound;
int main( int argc, char* args[] )
{
...
Mix_PlayMusic( Sound.getSound( "BGMusic" ), -1 );
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从上面的代码我不能完全确定你想要做什么。 函数“getSound”采用 Mix_Music 对象作为参数并返回相同的对象。 现在,根据一些推论,我假设您正在尝试通过字符串请求 BGMusic 对象。 有几种方法可以做到这一点,通过每个 Mix_Music 对象的 ID,按 ID 请求:
您可以使用每个对象的字符串标识符进行类似的操作。 归根结底,变量名和字符串标识符之间没有内置关系。 因此,您可以通过枚举(上面)或字符串标识符来实现这种关系。
希望这有帮助,再次不确定问题是什么。
From your code above I'm not absolutely certain what you are trying to do. The function 'getSound' takes a Mix_Music object as the parameter and returns the same object. Now from some deduction I assume that you are trying to request the BGMusic object via a string. There a few ways to do this, via IDs for each of Mix_Music objects, request by ID.:
You could do it similarly with string identifiers for each object. What it really comes down to is there is no built in relationship between a variable's name and a string identifier. So its up to you to implement this relationship either via an enum (above) or string identifiers.
Hope this helped, again not sure exactly what the question was.