Object Composition

Hey guys, i have two classes, viz:
Connection class in file "Connection.h" and
Statement class in file "Statement.h"
Connection class references Statement, since it creates and then returns the statement, viz:
 
Statement Connection::createStatement();


again, the Statement class reference the Connection that created it
1
2
3
4
5
6
7
private:
.
.
.
Connection *connection;
public:
Connection *Statement::getConnetion();


now, my query is in the following errors:
1
2
3

1>d:\programming\psqlconnector\psqlconnector\connection.h(13) : error C2079: 'SqlStatement' uses undefined class 'connector::sqldb::connector'
1>d:\programming\psqlconnector\psqlconnector\connection.h(13) : error C2086: 'int connector::sqldb::SqlStatement' : redefinition
Connection.h _must_ #include Statement.h in order to allow the declaration of Connection::createStatement() to compile.
But then Statement.h _must not_ include Connection.h, otherwise you end up with circular dependencies. Statement.h
can use pointers to Connections in declarations, but that is all.

So you can forward declare Connection in Statement.h:

 
class Connection;


prior to first use.

As for your second problem, instantiating variables in header files is a no-no. You'll need to move line 13 of connection.h
to a .cpp file.
hello marembo,

well 'SqlStatement' is different from 'Statement'. so you're missing the include that contains 'SqlStatement'?
Topic archived. No new replies allowed.