避免typedef c ++中的冲突声明错误 [英] Avoiding conflicting declaration errors in typedef c++

查看:4343
本文介绍了避免typedef c ++中的冲突声明错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让g ++忽略或处理冲突的typedef?

Is there a way I can make g++ ignore or work around conflicting typedefs?

背景

我正在为gridlab_d模拟器编写一些c ++代码。我的模型需要连接到一个c ++数据库,所以我使用mysql ++库。使用mysql ++库需要我链接到mysql库,所以我编译与

I'm writing some c++ code for the gridlab_d simulator. My model needs to connect to a c++ database, so I'm using the mysql++ library. use of the mysql++ library requires me to link to the mysql library, so i compile with

g ++ -I / usr / include / mysql -I / usr / local / include / mysql ++

问题:

在gridlab中的mysql.h和list.h typedef一个名为LIST的结构体。这是编译器错误

both mysql.h and list.h in gridlab typedef a struct to have the name LIST . Here is the compiler error

In file included from /usr/include/mysql/mysql.h:76, 
             from /usr/include/mysql++/common.h:182,
             from /usr/include/mysql++/connection.h:38,
             from /usr/include/mysql++/mysql++.h:56,
             from direct_data.cpp:21:
/usr/include/mysql/my_list.h: At global scope:
/usr/include/mysql/my_list.h:26: error: conflicting declaration 'typedef struct st_list LIST'
../core/list.h:22: error: 'LIST' has a previous declaration as 'typedef struct s_list LIST'

感谢您的帮助!

推荐答案

1)保留您当前的主程序

1) Keep your current main program

   EXAMPLE: "main.cpp"

2)为您的数据库访问写一个新的 / p>

2) Write a new module for your database access

   EXAMPLE: dbaccess.cpp, dbaccess.h

3)#includedbaccess.hin main.cpp

3) #include "dbaccess.h" in main.cpp

你不需要任何引用gridlab dbaccess代码;您不需要在您的dbaccess。*代码之外引用mySql或mySQL列表。

You don't need any references to gridlab in your dbaccess code; you don't need to refer to mySql or mySQL lists outside of your dbaccess.* code.

问题解决:

PS:
如果你真的需要某种类型的列表,你可以在不同的模块之间共享,我建议你使用像一个标准的C ++vector<>。 IMHO ...

PS: If you really need some kind of "list" that you can share between different modules, I'd encourage you to use something like a standard C++ "vector<>". IMHO...

这篇关于避免typedef c ++中的冲突声明错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆