Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with constructors

Status
Not open for further replies.

williegofar

Programmer
Feb 3, 2003
11
GB
Hi,
I've got a class in a DLL that has 4 constructors.


LINK_TO_DLL CDBF_OpenTable(
CDaoDatabase *_ciDaoDatabase,
CString _SQLString,
BOOL _ShowMessage = TRUE
);

LINK_TO_DLL CDBF_OpenTable(
CDaoDatabase *_ciDaoDatabase,
CString _SQLString,
CString _FieldName,
CString *_FieldText,
BOOL _ShowMessage = TRUE
);

LINK_TO_DLL CDBF_OpenTable(
CDaoDatabase *_ciDaoDatabase,
CString _Table,
LONG _ID,
BOOL _ShowMessage = TRUE
);

LINK_TO_DLL CDBF_OpenTable(
CDaoDatabase *_ciDaoDatabase,
CString _Table,
LONG _ID,
CString _FieldName,
CString *_FieldText,
BOOL _ShowMessage = TRUE
);


I've created a new class

class CReadTeam : public CDBF_OpenTable {
..... };

The constructor for this is;

CReadTeam::CReadTeam( CString _SQL_String )
: CDBF_OpenTable( &g_ciDaoDatabase, _SQL_String )

where g_ciDaoDatabase is a global variable.

The compiler is returning the following error message;
error C2512: 'CDBF_OpenTable' : no appropriate default constructor available

I can't understand why it doesn't realise that I am referring to the first constructor.

Would be grateful for any help. Thanks.
 
does CReadTeam inherit from CDBF_OpenTable? If not, taht costructor wont work properly. If you instead have an object of type CDBF_OpenTable, you will either need to make it a pointer or initialize the member variable in place of the constructor call.

Matt
 
Thanks for the reply.
CReadTeam does inherit from CDBF_OpenTable.
 
It seems strange... this constructor should be called

LINK_TO_DLL CDBF_OpenTable(
CDaoDatabase *_ciDaoDatabase,
CString _SQLString,
BOOL _ShowMessage = TRUE
);


Do you have multiple constructors? All constructors will need to call the parent class. Do you declare your CReadTeam as

// this should not work without a default constructor
CReadTeam myReadTeam;

???

If so, I suggest changing your constructor declaration to


class CReadTeam : public CDBF_OpenTable {
public:
CReadTeam(CString _SQL_String = "");
....
};

Matt
 
MORON!

problem solved.

Just before I decided to have my CReadTeam class inherit from my CDBF_OpenTable class, I thought about simply adding an instance of CDBF_OpenTable within CReadTeam's definition.
i.e.

protected:
CDBF_OpenTable maybe;

I then changed my mind, but forgot to remove this entry from the class definition. All the error messages I then encountered where relating to this line. It wasn't obvious though because the line number that the compiler was displayed was the constructor (in the .cpp).

Leason learnt!.
Thanks for your help Matt, and sorry for wasting your time.
 
It wasn't a waste of time. And you are not a moron :) Simple mistake that can easilly be overlooked

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top