I was wondering if there's a nack or hidden rules about this that I don't know about, because I'm struggling.
The situation is I have a class, 'User', which needs access to the database, which is accessed through 'class DBI'. Since the database connection is usually established before User is, the way I have it set up (for now) is to pass a reference to the initialised DBI class to the User constructor, which saves it as a member.
I've tried using both a reference member and a pointer member, but I keep getting an error on a member functions that use it. The pseudo-code below is the general way I'm doing it.
Code:
class DBI {
public:
void query();
};
class User {
DBI* mDBH;
public:
User( DBI& dbh ) : mDBH( &dbh ) {}
void do_stuff() {
mDBH->query();
}
};
void main()
{
DBI db;
User( db );
}
When compiling what's basically that, I get an error :
left of '->query' must point to class/struct/union/generic type
Is there something glaringly wrong with the above concept?