Thread: Re: [INTERFACES] libpq++ ---- PgDatabase instance problem
Well, this is where the problem comes because PgDatabase() is a protected constructor, myclass doesn't inherit from PgDatabase. In simple words: ============================================== class myclass { public: myclass(); private: PgDatabase db; } myclass::myclass():db(NULL){ some-other-stuff-goes-here }; =============================================== the above codes causes me trouble as I described below, any ideas how to fix it? I also tried PgDatabase db as a global variable and init it to be NULL, but this causes the same problem. Thanks. inkle --- Patrick Welche <prlw1@newn.cam.ac.uk> wrote: > inkle c wrote: > > > > Hi, > > > > I am writing a small class which has a PgDatabase > > instance as its private member, and in the > constructor, > > I init it to be NULL (i.e., > > myclass::myclass():PgDatabaseInstanceMember(NULL) > ), this causes a core > > dump, what's wrong with that? > > I'm not too sure what you want, but how about > > myclass::myclass():PgDatabase() > > ? > > Cheers, > > Patrick > __________________________________________________ Do You Yahoo!? Bid and sell for free at http://auctions.yahoo.com
inkle c wrote: > > Well, this is where the problem comes because PgDatabase() is a > protected constructor, myclass doesn't inherit from PgDatabase. In > simple words: > ============================================== > class myclass { > public: > myclass(); > private: > PgDatabase db; > } > > myclass::myclass():db(NULL){ > some-other-stuff-goes-here > }; > =============================================== > the above codes causes me trouble as I described > below, any ideas how to fix it? I also tried > PgDatabase db as a global variable and init it to > be NULL, but this causes the same problem. As far as I remember if you send NULL, you are saying that the string that PgDatabase uses is empty rather than being say "dbname=test", and that it should try to connect ?using defaults?, whereas if you just db(), you are saying, this instance isn't initialised, create it, but don't connect. I'm afraid I can't UTSL at the moment... Cheers, Patrick
Sounds like you can just have a pointer to PgDatabase in your class (private: PgDatabase* db_ptr;), and initialize that to the NULL pointer. Later on you instantiate PgDatabase with "new". --Yu Cao On Fri, 20 Aug 1999, inkle c wrote: > Well, this is where the problem comes because PgDatabase() is a > protected constructor, myclass doesn't inherit from PgDatabase. In > simple words: > ============================================== > class myclass { > public: > myclass(); > private: > PgDatabase db; > } > > myclass::myclass():db(NULL){ > some-other-stuff-goes-here > }; > =============================================== > the above codes causes me trouble as I described > below, any ideas how to fix it? I also tried > PgDatabase db as a global variable and init it to > be NULL, but this causes the same problem. > > Thanks. > > inkle > > --- Patrick Welche <prlw1@newn.cam.ac.uk> wrote: > > inkle c wrote: > > > > > > Hi, > > > > > > I am writing a small class which has a PgDatabase > > > instance as its private member, and in the > > constructor, > > > I init it to be NULL (i.e., > > > myclass::myclass():PgDatabaseInstanceMember(NULL) > > ), this causes a core > > > dump, what's wrong with that? > > > > I'm not too sure what you want, but how about > > > > myclass::myclass():PgDatabase() > > > > ? > > > > Cheers, > > > > Patrick > > > > __________________________________________________ > Do You Yahoo!? > Bid and sell for free at http://auctions.yahoo.com > > > ************ > >