1

I've been following this tutorial, but I get some errors that I don't quite understand. I'm pretty much just have 2 functions, one for closing it, and one for opening it. I'm clueless as to why these errors are here.

DatabaseWriter.h:

#ifndef FILEPARSER_H
#define FILEPARSER_H

#include "DatabaseWriter.h"

using namespace std;

class DatabaseWriter
{
private:

public:
    void CloseConn(PGconn *conn);
    PGconn DatabaseWriter::*ConnectDB ();

    DatabaseWriter ();

};

#endif

DatabaseWriter.cpp

#include "stdafx.h"
#include <string>
#include <string>
#include "libpq-fe.h"
#include "DatabaseWriter.h"

using namespace std;

const char* CONNECTIONSTRING = "user=postgres password=superman dbname=poker hostaddr=127.0.0.1 port=5432";

void DatabaseWriter::CloseConn (PGconn *conn)
{
    PQfinish(conn);
    getchar();
    exit(1);
}

PGconn DatabaseWriter::*ConnectDB ()
{
    PGconn *conn = NULL;

    // Make a connection to the database
    conn = PQconnectdb(CONNECTIONSTRING);

    // Check to see that the backend connection was successfully made
    if (PQstatus(conn) != CONNECTION_OK)
    {
        printf("Connection to database failed");
        CloseConn(conn);
    }

    printf("Connection to database - OK\n");

    return conn;
}

I defined CloseConn earlier myself, so it shouldn't be undefined.

Error 1

The return type of ConnectDB is PGconn, conn is a PGconn, so I don't see why it shouldn't return it.

Error 2

Obviously there are things I'm blatantly looking over, so thanks for your effort.

1 Answer 1

1

You don't need the DatabaseWriter:: inside the class declaration, only in the definition. I also suggest you take a closer look at that definition, especially where the * is in it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.