我有无法在一台计算机上编译的代码。它在我的电脑上工作,但在另一台电脑上却不起作用。这个错误是“重新定义typdef cplx”,尽管我对每个头文件都有保护,并且对typdef的每个定义都有保护:
#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif为什么会出现这样的问题?以下是两个头文件。布拉什:
#ifndef BLAS_H
#define BLAS_H
#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif
//declaration of functions
#endif和翻版。h:
#ifndef LAPACK_H
#define LAPACK_H
#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif
//declarations of functions
#endif问题是,当我将两者都包括在内时,会产生这个错误吗?
发布于 2015-09-12 02:38:03
您的警卫保护相同的包含文件被包含两次,但您有两个不同的包含文件与两个不同的警卫,你定义cplx在每一个。
您需要在每个包含文件中为该类型设置一个单独的保护程序,如下所示:
#ifndef CPLX
#define CPLX
#ifdef __cplusplus
#include <complex>
#include <cmath>
typedef std::complex<double> cplx;
#else
#include <tgmath.h>
typedef double complex cplx;
#endif
//declarations of functions
#endifhttps://stackoverflow.com/questions/32534424
复制相似问题