VC編譯錯誤:'waveformat_tag' : 'struct' type redefinition
錯誤信息: : error C2011: 'waveformat_tag' : 'struct' type redefinition
: error C2011: 'pcmwaveformat_tag' : 'struct' type redefinition
: error C2061: syntax error : identifier 'LPCWAVEFORMATEX'
: error C2061: syntax error : identifier 'LPCWAVEFORMATEX'
解決方法:
這是頭文件包含順序不正確所致。原先的文件包含順序爲:
#include <mmreg.h>
#include <mmsystem.h>
#include <msacm.h>
可以看到,mmreg.h文件中有如下定義:
#ifndef WAVE_FORMAT_PCM
typedef struct waveformat_tag ××××
而WAVE_FORMAT_PCM在mmsystem.h中有定義,但是在#include <mmreg.h>之前,WAVE_FORMAT_PCM還是沒有被定義,所以,typedef struct waveformat_tag ××××語句生效,之後mmsystem.h中再次定義waveformat_tag,於是出現重複定義。
正確的包含順序是:
#include <mmsystem.h>
#include <mmreg.h>
#include <msacm.h>
(包含靜態庫)
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "Msacm32.lib")