【发布时间】:2016-04-11 22:22:16
【问题描述】:
我正在使用一个名为 SDL_mixer 的声音库。 GCC 抱怨我向前声明了一个指针结构?我做错了什么?
Mix_Music **music; // music[2] must be a pointer to fit any random file
music = new Mix_Music[3];
music[2] = Mix_LoadMUS("fire.ogg");
GCC 返回:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
xxx.cpp||In function 'int SDL_main(int, char**)':|
xxx.cpp|28|error: invalid use of incomplete type 'Mix_Music {aka struct _Mix_Music}'|
SDL_mixer.h|131|error: forward declaration of 'Mix_Music {aka struct _Mix_Music}'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
edit:我需要动态分配结构,因为可能会加载数千个文件。堆栈内存不行。
【问题讨论】:
-
Mix_Music* music[3]; music[2] = Mix_LoadMUS("fire.ogg"); -
典型的堆栈大约是一兆字节。那是 128k 指针。
-
我几乎不会称 SDL_mixer“晦涩难懂”!
-
不确定它有多晦涩,但使用保留名称并不酷。
标签: c++ pointers struct typedef