[英]two different libraries using the same name types
I am using two different c++ libraries. 我正在使用两个不同的c ++库。 Both libraries use a name for a type, let's say, called fofo.
这两个库都使用一个名称作为类型,即fofo。 In lib1.h:
在lib1.h中:
typedef short fofo;
In lib2.h: 在lib2.h中:
namespace LIB2
{
typedef struct
{
uint16_t toto;
} fofo;
}
using LIB2::fofo;
I have a C++ project/VS 2008 that uses both libraries: when I do in my project 我有一个使用两个库的C ++项目/ VS 2008:在我的项目中使用时
#include lib1.h
I get the error: error C2874: using-declaration causes a multiple declaration 我收到错误:错误C2874:using-declaration导致多个声明
I would like to use in my project both libraries but without making any change to these libraries. 我想在我的项目中使用两个库,但不对这些库进行任何更改。 The only thing that I can modify is my VS2008 project.
我唯一可以修改的是我的VS2008项目。 Thanks for your help!
谢谢你的帮助!
this (dirty) workaround will probably work (depending how the headers are being used) 这个(肮脏的)解决方法可能会起作用(取决于标题的使用方式)
instead of including lib1.h directly ,wrap it by making a new headerfile 而不是直接包含lib1.h,而是通过制作一个新的头文件来包装它
lib1wrapped.h lib1wrapped.h
#define fofo fofo_wrap
#include "lib1.h" // OR <lib1.h>
#undef fofo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.