【发布时间】:2014-05-22 01:27:46
【问题描述】:
我最近开始阅读有关 alsa api 的信息。我正在尝试编写一个 C++ 类,它打开默认设备并读取基本参数,如最大速率、通道数等。
我的类头文件是:
#include <alsa/asoundlib.h>
#include <iostream>
class AlsaParam{
snd_pcm_t* pcm_handle;
snd_pcm_hw_params_t* hw_param;
....
public:
int pcm_open();
.....
};
pcm_open() 内部
int AlsaParam::pcm_open(){
int err = snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, 0);
if(err > -1)
std::cout << pcm_handle->name << std::endl; //Just to test if it works
return err;
}
我收到以下错误:
error: invalid use of incomplete type ‘snd_pcm_t {aka struct _snd_pcm}’
std::cout << pcm_handle->name << std::endl;
^
In file included from /usr/include/alsa/asoundlib.h:54:0,
from alsa_param.h:4,
from alsa_param.cpp:1:
/usr/include/alsa/pcm.h:341:16: error: forward declaration of ‘snd_pcm_t {aka struct _snd_pcm}’
typedef struct _snd_pcm snd_pcm_t;
^
从这个错误中,我了解到 asoundlib.h 仅将 typedef 用于 struct snd_pcm_t,但它是在其他地方定义的。我对么?有没有办法解决这个问题?一般来说,如果我们在 C++ 类中包含一些 c 库函数,哪些是要记住/避免的?谢谢
【问题讨论】: