简体   繁体   English

两个使用相同名称类型的不同库

[英]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.

相关问题 一起使用两个同名的 Arduino 库 - using two Arduino libraries with the same name together 使用 CMake 包含具有相同名称但来自不同库的标头 - Include headers with same name but from different libraries using CMake 当两个库有同名的变量类型时,如何正确定义变量类型? - When two libraries have variable types with the same name, how to define the variable type correctly? 同一声明有两种不同类型 - Same declaration two different types 如何拥有两个具有相同名称但返回类型不同的纯虚拟方法 - How to have two pure virtual methods with the same name but different return types 由于多个抽象基类,实现两个具有相同名称但不同的非协变返回类型的函数 - Implement two functions with the same name but different, non-covariant return types due to multiple abstract base classes 为两种不同类型专门化相同的模板定义 - Specializing The Same Template Definition For Two Different Types 具有相同数据但类型不同的两个向量 - Two vectors with same data but different types 在同一个项目中使用两个不同的数学库会混淆 Visual C++ - Using two different math libraries in the same project confuses Visual C++ 合并两个C++同名库function - Merging two C++ libraries with the same name function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM