C++ SDL Mixer Mix_Music:不允许不完整的类型

发布于 2024-10-03 08:06:26 字数 244 浏览 5 评论 0原文

每当我尝试创建 Mix_Music 实例时,都会收到此错误:“不允许使用不完整的类型”。

但是,在调用 Mix_LoadMUS(file); 之前,我需要获取指针 music 的地址。

代码:

Mix_Music *music;

/* I need the memory address here */

music = Mix_LoadMUS(file);

我该怎么做?

whenever I try to create Mix_Music instance, I get this error: "incomplete type is not allowed".

However, I need to get the address of the pointer music before calling Mix_LoadMUS(file);

Code:

Mix_Music *music;

/* I need the memory address here */

music = Mix_LoadMUS(file);

How do I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2024-10-10 08:06:26

不完整类型

#include "SDL_mixer.h" 应该没问题1,2

如果没有 SDL 包含来告诉编译器这些 SDL 引用(Mix_Musi、Mix_LoadMUS 等)也引用了什么,编译器就无法编译与 SDL 相关的代码。请参阅 kekkai.org/roger3 上的 SDL_Mixer 教程,它有一个完整的示例。

1 SDL 包含文件
2 Mix_LOadMUS
3 带有完整示例的 SDL 教程

--

更新:使用音乐数组Items

这是一个示例,说明如何从线程代码内或在词法上与分配的任何地方访问指向 Mix_ Music 的特定指针。指针变量。实际的实现可能需要使用动态数组分配,并且需要添加对文件未找到或加载失败等的错误处理。

MEnt.h 初始化和线程模块的通用 iinclude 文件:

#include <cstdlib>
#include "SDL.h"
#include "SDL_mixer.h"

enum { MAXENTRIES=1024 };
struct MEnt{ 
       Mix_Music * music;
       char *filename;
};

extern MEnt Marray[MAXENTRIES];
extern int Mselected;

程序初始化:

#include "MEnt.h"

// Alocate space for array of music items

MEnt Marray[MAXENTRIES]; 
int Mselected=-1;

在线程的代码,包括:

#include "MEnt.h"
// Return a pointer for the selected music item:
// Allocate new Mix_Music* if not already done,
// otherwise return the already allocated pointer.
Mix_Music *getSelected(){
    Mix_Music *music;

    if(Mselected >= 0 && Mselected < MAXENTRIES){
      struct MEnt ¤t=Marray[Mselected];
       if(!(music=current.music) &&
                  (current.filename!=NULL))
          music=current.music=
                  Mix_LoadMUS(current.filename);
    }
    return music;
}      

Incomplete Type

#include "SDL_mixer.h" and it should be fine1,2.

The compiler is not capable of compiling SDL-related code without the SDL includes to tell it what those SDL refernces (Mix_Musi, Mix_LoadMUS, etc) refer too. See the SDL_Mixer Tutorial at kekkai.org/roger3 It has a complete example.

1 SDL Include file
2 Mix_LOadMUS
3 SDL Tutorial with complete example

--

Update: Using an Array of Music Items

This is an example of how to access a particular pointer to Mix_ Music from within a thread's code, or in any place lexically separate from the allocation of the pointer variable. An actual implementation may want to use dynamic array allocation and needs to add error handling for file-not-found or failed-to-load, etc.

MEnt.h A common iclude file for the initilization and thread modules:

#include <cstdlib>
#include "SDL.h"
#include "SDL_mixer.h"

enum { MAXENTRIES=1024 };
struct MEnt{ 
       Mix_Music * music;
       char *filename;
};

extern MEnt Marray[MAXENTRIES];
extern int Mselected;

Program initialization:

#include "MEnt.h"

// Alocate space for array of music items

MEnt Marray[MAXENTRIES]; 
int Mselected=-1;

In the thread's code,include:

#include "MEnt.h"
// Return a pointer for the selected music item:
// Allocate new Mix_Music* if not already done,
// otherwise return the already allocated pointer.
Mix_Music *getSelected(){
    Mix_Music *music;

    if(Mselected >= 0 && Mselected < MAXENTRIES){
      struct MEnt ¤t=Marray[Mselected];
       if(!(music=current.music) &&
                  (current.filename!=NULL))
          music=current.music=
                  Mix_LoadMUS(current.filename);
    }
    return music;
}      
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文