我有一个程序,我不明白它是如何工作的。这是它的一部分。 我不明白行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