Re: How to create shared_ptr for PGconn?

From: Dmitry Igrishin <dmitigr(at)gmail(dot)com>
To: Chengyu Fan <chengyu(dot)fan(at)hotmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to create shared_ptr for PGconn?
Date: 2015-03-16 18:46:39
Message-ID: CAAfz9KOhwheNns+SHB0O=TPtX-Q29U243VigZEUrwMDK+36pBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2015-03-16 19:32 GMT+03:00 Chengyu Fan <chengyu(dot)fan(at)hotmail(dot)com>:

> 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<PGconn> pConn(conn);
> -----------
>
> Error messages for the code above:
>
> *main.cpp:153:27: **note: *in instantiation of function template
> specialization 'std::__1::shared_ptr<pg_conn>::shared_ptr<pg_conn, void>'
> requested here
>
> std::shared_ptr<PGconn> 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 <memory>

#include <libpq-fe.h>

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

return 0;
}

--
// Dmitry.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-03-16 18:55:27 Re: assessing parallel-safety
Previous Message Robert Haas 2015-03-16 18:38:34 Re: assessing parallel-safety