Re: [HACKERS] How to create shared_ptr for PGconn?

2015-03-16 Thread Dmitry Igrishin
2015-03-16 19:32 GMT+03:00 Chengyu Fan :

> Hi,
>
> Does anyone know how to create the shared_ptr for PGconn? I always get
> compile errors ...
>
> Below is my code:
> ---
> const char * dbInfo = "xxx";
> PGconn *conn = PGconnectdb(dbInfo);
> if (PGstatus(conn) != CONNECTION_OK) {
> std::cout << PQerrorMessage(conn) << std::endl;
> return 1;
> }
>
> std::shared_ptr pConn(conn);
> ---
>
> Error messages for the code above:
>
> *main.cpp:153:27: **note: *in instantiation of function template
> specialization 'std::__1::shared_ptr::shared_ptr'
> requested here
>
>   std::shared_ptr pConn(rawConn);
>
>
> */usr/local/Cellar/postgresql/9.4.1/include/libpq-fe.h:129:16: note: *forward
> declaration of 'pg_conn'
>
> typedef struct pg_conn PGconn;
>
The complete example below:

#include 

#include 

int main(int argc, char *argv[])
{
  PGconn* cn = PQconnectdb("");
  std::shared_ptr shared_cn(cn, &PQfinish);

  return 0;
}



-- 
// Dmitry.


[HACKERS] How to create shared_ptr for PGconn?

2015-03-16 Thread Chengyu Fan
Hi,
Does anyone know how to create the shared_ptr for PGconn? I always get compile 
errors ...
Below is my code:---const char * dbInfo = "xxx";PGconn 
*conn = PGconnectdb(dbInfo);if (PGstatus(conn) != CONNECTION_OK) {std::cout 
<< PQerrorMessage(conn) << std::endl;return 1;}
std::shared_ptr pConn(conn);---
Error messages for the code above:















main.cpp:153:27: note: in instantiation of function template specialization 
'std::__1::shared_ptr::shared_ptr' requested here
  std::shared_ptr pConn(rawConn);
/usr/local/Cellar/postgresql/9.4.1/include/libpq-fe.h:129:16: note: forward 
declaration of 'pg_conn'








typedef struct pg_conn PGconn;

Thanks,Chengyu