小编suj*_*eet的帖子

C++ 11中具有C链接的复杂类型

我需要将C库的头部包含在我的C++ 11代码中.现在,标题提供了涉及大量double complex所有地方的例程和数据结构.例如,

#include <complex.h>
//..
typedef struct parameters
{
    // ...
    double complex Vud;
} parameters;
// ...
double complex polylog(int n, int m, double x);
Run Code Online (Sandbox Code Playgroud)

我把这个文件带到我的C++ 11源代码中extern "C" { #include "include.h" }(这是实际的文件名,信不信由你).如果我添加了-std = c ++ 11,那么g ++(试过4.7.3和4.8.2)和clang(3.3)就会疯狂.

数百万行g ++错误包括:

include/g++-v4/cmath:98:3: error: template with C linkage
Run Code Online (Sandbox Code Playgroud)

并且clang给出:

cmath:84:3: error: declaration conflicts with target of using declaration already in scope
  abs(double __x)
  ^
/usr/include/stdlib.h:773:12: note: target of using declaration
extern int abs (int __x) __THROW __attribute__ …
Run Code Online (Sandbox Code Playgroud)

c c++ complex-numbers complextype c++11

5
推荐指数
1
解决办法
2395
查看次数

标签 统计

c ×1

c++ ×1

c++11 ×1

complex-numbers ×1

complextype ×1