我有一個程序,我不明白它是如何工作的。這是它的一部分。 我不明白行typedef void *COMPLEX
,命令this
和爲什麼struct COMPLEX_IMPL
正在使用。爲什麼在此界面中使用`typedef void * COMPLEX`?
#ifndef _COMPLEX_H
#define _COMPLEX_H
typedef void *COMPLEX;
COMPLEX NewCOMPLEX (double a, double b);
void DeleteCOMPLEX(COMPLEX this);
double GetA (COMPLEX this);
double GetB (COMPLEX this);
COMPLEX AddComplex (COMPLEX c1, COMPLEX c2, COMPLEX res);
COMPLEX MultComplex (COMPLEX c1, COMPLEX c2, COMPLEX res);
#endif /* _COMPLEX_H */
#ifndef _COMPLEX_H
#define _COMPLEX_H
typedef void *COMPLEX;
COMPLEX NewCOMPLEX (double a, double b);
void DeleteCOMPLEX(COMPLEX this);
double GetA (COMPLEX this);
double GetB (COMPLEX this);
COMPLEX AddComplex (COMPLEX c1, COMPLEX c2, COMPLEX res);
COMPLEX MultComplex (COMPLEX c1, COMPLEX c2, COMPLEX res);
#endif /* _COMPLEX_H */
#include <stdio.h>
#include "complex.h"
struct COMPLEX_IMPL { double a; double b; };
double GetA(COMPLEX this) {
struct COMPLEX_IMPL *this_impl = (struct COMPLEX_IMPL*)this;
return this_impl->a;
}
由此我猜想這是C++?無論如何,請看這個應用程序正在使用的語言的基本知識,你應該能夠自己回答你的問題。 – steffinchen 2012-02-23 11:41:16
@steffinchen相反,由於使用'this'作爲一個普通的標識符,這是一個C程序,它是無效的C++。我建議你更仔細地研究C++的基礎知識。如果你不做這種嘲弄的評論,那也會更好;這裏使用'void *'不是一個基本的問題。 – Gilles 2012-02-24 10:45:39