I have two classes, Main class and a connection class as:
Conn.cpp:
#include "conn.h"
#include <postgresql/libpq-fe.h>
Conn::getConnection()
{
connStr = "dbname=test user=postgres password=Home hostaddr=127.0.0.1 port=5432";
PGconn* conn;
conn = PQconnectdb(connStr);
if(PQstatus(conn) != CONNECTION_OK)
{
cout << "Connection Failed.";
PQfinish(conn);
}
else
{
cout << "Connection Successful.";
}
return conn;
}
conn.h
#ifndef CONN_H
#define CONN_H
#include <postgresql/libpq-fe.h>
class Conn
{
public:
const char *connStr;
Conn();
PGconn getConnection();
void closeConn(PGconn *);
};
Main.cpp
#include <iostream>
#include <postgresql/libpq-fe.h>
#include "conn.h"
using namespace std;
int main()
{
PGconn *connection = NULL;
Conn *connObj;
connection = connObj->getConnection();
return 0;
}
error: invalid use of incomplete type ‘PGconn {aka struct pg_conn}’
error: forward declaration of ‘PGconn {aka struct pg_conn}’
Any help?
In your conn.cpp,
conn::getConnection()has no return type. From your code, I guess you need to return a pointer to PGconn:conn.h
conn.cpp