[問題] typedef struct 的問題?
剛有稍微爬一下文~不過不確定我想的對不對!!
以下是我的程式:
#define MixtureNum 17
#define FeatDim 17
#define PatternNum 2
typedef struct{
double **GMMMean;
double **GMMVar;
}GMM;
GMM *Model;
Model=(GMM *)malloc(PatternNum*sizeof(GMM));
Model[index].GMMMean=(double **)malloc(MixtureNum*sizeof(double *));
Model[index].GMMVar=(double **)malloc(MixtureNum*sizeof(double *));
for(i=0;i<MixtureNum;i++){
Model[index].GMMMean[i]=(double *)malloc(FeatDim*sizeof(double));
Model[index].GMMVar[i]=(double *)malloc(FeatDim*sizeof(double));
}
.
.
. 以下略過!!
這樣去compiler & linker 完全不會錯~那如果我今天多加了這些東西在上面:
GMM *Model,*New_Model; (多加了 *New_Model 這項!! )
New_Model=(GMM *)malloc(1*sizeof(GMM));
New_Model.GMMMean=(double **)malloc(MixtureNum*sizeof(double *));
New_Model.GMMVar=(double **)malloc(MixtureNum*sizeof(double *));
for(i=0;i<MixtureNum;i++){
New_Model.GMMMean[i]=(double *)malloc(FeatDim*sizeof(double));
New_Model.GMMVar[i]=(double *)malloc(FeatDim*sizeof(double));
}
在這樣情況下 compiler 會出現4個錯誤 都是顯示
"error C2228: left of '.GMMMean' must have class/struct/union type"
"error C2228: left of '.GMMVar' must have class/struct/union type"
"error C2228: left of '.GMMMean' must have class/struct/union type"
"error C2228: left of '.GMMVar' must have class/struct/union type"
會出現錯誤是因為 struct 在C++裡面的資料型態都為public的關係嗎?
因為它好像只認得Model裡面的東西 不認得New_Model裡面的東西!!
如果真是這樣 那如果我要宣告ㄧ個跟GMMㄧ模一樣的結構只能再重新定義囉!?
ex:
typedef struct{
double **BBB;
double **CCC;
}TTT;
TTT *New_Model;
.
.
.
這樣對嗎? 麻煩大家幫我解惑一下!! thanks!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.124.72.230
推
05/29 20:18, , 1F
05/29 20:18, 1F
→
05/29 20:18, , 2F
05/29 20:18, 2F
→
05/29 21:06, , 3F
05/29 21:06, 3F
→
05/29 21:06, , 4F
05/29 21:06, 4F
推
05/29 21:14, , 5F
05/29 21:14, 5F
推
05/30 14:11, , 6F
05/30 14:11, 6F
→
05/30 14:14, , 7F
05/30 14:14, 7F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章