Using c library variable/struct member in C++ class member function -


i started reading alsa api. trying write c++ class opens default device , reads basic parameters maximum rate, number of channels etc.

my class header file is:

#include <alsa/asoundlib.h> #include <iostream> class alsaparam{     snd_pcm_t* pcm_handle;     snd_pcm_hw_params_t* hw_param;     ....      public:       int pcm_open();        .....  }; 

inside 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 test if works  return err; } 

i following error:

error: invalid use of incomplete type ‘snd_pcm_t {aka struct _snd_pcm}’ std::cout << pcm_handle->name << std::endl;                        ^  in file included /usr/include/alsa/asoundlib.h:54:0,              alsa_param.h:4,              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;             ^ 

from error understood asoundlib.h uses typedef struct snd_pcm_t defined somewhere else. correct? there way solve problem? in general if including c library functions in c++ class things remember/ avoid? thanks

the layout of struct _snd_pcm deliberately hidden programs because might change in new library version.

to pcm device's name, call snd_pcm_name:

cout << snd_pcm_name(pcm_handle) << endl; 

(pretty in alsa needs such function call.)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -