One of my class members has void * type:
void * conn;
In Connection method I set connection to Firebird database and set conn member like this:
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. So, this is what happens. In another method I use conn member to fetch data from a particular 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 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:
...
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::Databaseis a typedef ofIBPP::IDatabase *
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*
See http://www.ibpp.org/reference/guidelines#ibpp_smart_pointers_reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With