冲突声明(conflicting declaration)解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_30440627/article/details/84328446

使用到的2个库文件,重复定义了同名的数据类型。

1、在后一个引用的定义的地方(比如uint64这个类型被重复定义)
 

#ifdef uint64

#undef uint64

#define unsigned long long uint64 

将前一个定义“undefine”,重新定义一个。这个要求冲突的2个定义必须是相同类型(都是unsigned long long),不然前一个文件中使用到的地方就会报错。

2、新建一个中间文件,interface.h和interface.cc

在.h文件中,定义新的数据类型和方法,内容为使用到的库2的数据类型和方法。在其他文件调用库2方法的地方,全部转换为调用.h中新定义的数据类型和方法。其中void myset()函数内部调用库2中的方法。

class interface{
public:
    struct a{
        sss
    }

    void myset();

在.cc文件中

#include "interface.h"

extern {
    库2.h
}

extern 库2的数据类型
extern 库2中使用到的方法

void interface::myset(){
    库2中的方法;
}

通过这种方法将库2和使用的地方隔离开来,完全通过interface来中转。

猜你喜欢

转载自blog.csdn.net/sinat_30440627/article/details/84328446