Invalid conversion from and to void * when using ibpp in C ++
One of my class members is of void *
type:
void * conn;
In the Connection
method, I established a database connection Firebird
and set a member conn
like this:
IBPP::Database conn = IBPP::DatabaseFactory(host, dbname, user, pass);
conn->Connect();
this->conn = static_cast<void *>(conn);
This way works well for several other databases, but breaks when I try to use it with Firebird
. So here's what's going on. In another method, I use a member conn
to retrieve data from a specific database. When it comes to Firebird
, I do it like this:
IBPP::Transaction tr = IBPP::TransactionFactory(static_cast<IBPP::Database>(this->conn));
However, this line of code shows an error:
error: invalid conversion from 'void *' to 'IBPP::IDatabase *'
I don't know what I am doing wrong.
EDIT
Here are some code snippets from 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's a playable test file:
#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 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);
source to share
In a comment, you say:
Well guys please pay attention to what the
IBPP::Database
typedef isIBPP::IDatabase *
No, it is not.
Look again:
error: invalid static_cast from type IBPP::Database
{aka IBPP::Ptr<IBPP::IDatabase>}
This is a typedef for , not , so it is a smart pointer and does not convert to Ptr<IDatabase>
IDatabase*
void*
See http://www.ibpp.org/reference/guidelines#ibpp_smart_pointers_reference
source to share