我有两个文件,即。 main.cpp和myLib.h。 myLib.h的内容如下:
#ifndef MYLIB_H
#define MYLIB_H
#include <math.h>
#include <complex.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef float complex cfloat;
typedef double complex cdouble;
#define myFunc_cfloat(r,i) ((float)(r) + ((float)(i))*I)
#define myFunc_cdouble(r,i) ((double)(r) + ((double)(i))*I)
#ifdef __cplusplus
} // extern "C"
#endif
#endif
main.cpp的内容如下。
#include "myLib.h"
#include <iostream>
int main()
{
std::cout<<"This file need to be compiled using C++11\n";
int a = 10;
int b = 5;
auto c = a+b;
std::cout<<"c= "<<c<<std::endl;
return 0;
}
main.cpp需要使用C ++ 11标准编译器运行。但是,当我使用带有标志--std=c++11
的g ++运行它时,出现以下错误。
In file included from main.cpp:1:0:
myLib.h:10:23: error: expected initializer before ‘cfloat’
typedef float complex cfloat;
^~~~~~
myLib.h:11:24: error: expected initializer before ‘cdouble’
typedef double complex cdouble;
如果我使用标志--std=c++03
,并删除“ auto
”关键字,以便main.cpp不再需要C + 11,它将起作用。
但是,我有权使用C ++ 11进行编译。
有什么可能的解决方案?