[英]Invalid conversion from and to void * when using ibpp in c++
One of my class members has void *
type: 我的一个班级成员有
void *
类型:
void * conn;
In Connection
method I set connection to Firebird
database and set conn
member like this: 在
Connection
方法中,我设置与Firebird
数据库的连接并设置conn
成员,如下所示:
IBPP::Database conn = IBPP::DatabaseFactory(host, dbname, user, pass);
conn->Connect();
this->conn = static_cast<void *>(conn);
This way of doing things works well for other multiple databases, but breaks when I try to use it with Firebird
. 这种做事方式适用于其他多个数据库,但在我尝试将其与
Firebird
一起使用时会中断。 So, this is what happens. 所以,这就是发生的事情。 In another method I use
conn
member to fetch data from a particular database. 在另一种方法中,我使用
conn
成员从特定数据库中获取数据。 When it comes to Firebird
, I do it like this: 说到
Firebird
,我这样做:
IBPP::Transaction tr = IBPP::TransactionFactory(static_cast<IBPP::Database>(this->conn));
However, this line of code results in an error message: 但是,这行代码会导致错误消息:
error: invalid conversion from 'void *' to 'IBPP::IDatabase *'
I do not know what I'm doing wrong. 我不知道我做错了什么。
EDIT 编辑
Here are some code snippets from ibpp.h
: 以下是
ibpp.h
一些代码片段:
...
class IDatabase;
typedef Ptr<IDatabase> Database;
...
class IDatabase{
public:
virtual const char * ServerName() const = 0;
virtual const char * DatabaseName() const = 0;
...
virtual void Connect() = 0;
...
}
EDIT 编辑
Here is a reproducible testcase: 这是一个可重现的测试用例:
#define IBPP_LINUX
#include <ibpp.h>
int main(){
//#1. No errors
IBPP::Database conn = IBPP::DatabaseFactory("localhost","/var/lib/firebird/2.5/data/reestr.fdb","SYSDBA","root");
conn->Connect();
conn->Disconnect();
//end of #1.
//#2. Here we get errors.
void * cn;
IBPP::Database conn2 = IBPP::DatabaseFactory("localhost","/var/lib/firebird/2.5/data/reestr.fdb","SYSDBA","root");
conn2->Connect();
cn = static_cast<void *>(conn2);
conn2->Disconnect();
return 0;
}
and this is the error message, that I get when I try to compile it: 这是我尝试编译时得到的错误消息:
error: invalid static_cast from type IBPP::Database
{aka IBPP::Ptr<IBPP::IDatabase>} to type void *
The error message points to this line of code: 错误消息指向此行代码:
cn = static_cast<void *>(conn2);
In a comment you say: 在评论中你说:
well, guys, please, pay attention to the fact that
IBPP::Database
is a typedef ofIBPP::IDatabase *
伙计们,请注意
IBPP::Database
是IBPP::IDatabase *
的typedef这一事实
No it isn't. 不,不是。
Look again: 再看一遍:
error: invalid static_cast from type IBPP::Database
{aka IBPP::Ptr<IBPP::IDatabase>}
It's a typedef for Ptr<IDatabase>
, not IDatabase*
, so it is a smart pointer, and not convertible to void*
它是
Ptr<IDatabase>
的typedef,而不是IDatabase*
,因此它是一个智能指针,不能转换为void*
See http://www.ibpp.org/reference/guidelines#ibpp_smart_pointers_reference 请参阅http://www.ibpp.org/reference/guidelines#ibpp_smart_pointers_reference
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.