Class name

W

worlman385

Why the following header file - database.h must put

class Database;
class Table;

at the beginning?

Is that if I define multiple Class in a single .h file, then I need to
put all Class name at the beginning?

================
class Database;
class Table;

class Database
{
public:
CnnPtr m_Cnn;
char m_ErrStr[500];
Database();
bool Open(char* UserName, char* Pwd,char* CnnStr);
bool Execute(char* CmdStr, Table& Tbl);
void GetErrorErrStr(char* ErrStr);
};

class Table{
public:
RecPtr m_Rec;
char m_ErrStr[500];
Table();
void GetErrorErrStr(char* ErrStr);
int ISEOF();
HRESULT MoveNext();
HRESULT MovePrevious();
HRESULT MoveFirst();
HRESULT MoveLast();

bool Get(char* FieldName, char* FieldValue);
bool Get(char* FieldName,SYSTEMTIME& FieldValue);
bool Get(char* FieldName,float& FieldValue);
bool Get(char* FieldName,double& FieldValue);
bool Get(char* FieldName,double& FieldValue,int Scale);
bool Get(char* FieldName,long& FieldValue);

BOOL VariantTimeToSystemTimeWithMilliseconds (/*input*/ double
dVariantTime, /*output*/SYSTEMTIME *st);
};
 
S

Sharad

Why the following header file - database.h must put

class Database;
class Table;

at the beginning?

Is that if I define multiple Class in a single .h file, then I need to
put all Class name at the beginning?

No. Read about forward declarations in your favorite C++ book.

Sharad
 
B

Barry

Why the following header file - database.h must put

class Database;
class Table;

at the beginning?

Is that if I define multiple Class in a single .h file, then I need to
put all Class name at the beginning?

================
class Database;
class Table;

class Database
{
public:
        CnnPtr m_Cnn;
        char m_ErrStr[500];
        Database();
        bool Open(char* UserName, char* Pwd,char* CnnStr);
        bool Execute(char* CmdStr, Table& Tbl);

^^^^^^^^
It's because you use "Table" as reference here, then you need
"forward declaration" to let complier know this is a class name.

Maybe you can have a look at
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.12
        void GetErrorErrStr(char* ErrStr);

};

class Table{
public:
        RecPtr m_Rec;
        char m_ErrStr[500];
        Table();
        void GetErrorErrStr(char* ErrStr);
        int ISEOF();
        HRESULT MoveNext();
        HRESULT MovePrevious();
        HRESULT MoveFirst();
        HRESULT MoveLast();

        bool Get(char* FieldName, char* FieldValue);
        bool Get(char* FieldName,SYSTEMTIME& FieldValue);
        bool Get(char* FieldName,float& FieldValue);
        bool Get(char* FieldName,double& FieldValue);
        bool Get(char* FieldName,double& FieldValue,int Scale);
        bool Get(char* FieldName,long& FieldValue);

    BOOL VariantTimeToSystemTimeWithMilliseconds (/*input*/ double
dVariantTime, /*output*/SYSTEMTIME *st);

};
 
S

Saeed Amrollahi

Why the following header file - database.h must put

class Database;
class Table;

at the beginning?

Is that if I define multiple Class in a single .h file, then I need to
put all Class name at the beginning?

================
class Database;
class Table;

class Database
{
public:
        CnnPtr m_Cnn;
        char m_ErrStr[500];
        Database();
        bool Open(char* UserName, char* Pwd,char* CnnStr);
        bool Execute(char* CmdStr, Table& Tbl);
        void GetErrorErrStr(char* ErrStr);

};

class Table{
public:
        RecPtr m_Rec;
        char m_ErrStr[500];
        Table();
        void GetErrorErrStr(char* ErrStr);
        int ISEOF();
        HRESULT MoveNext();
        HRESULT MovePrevious();
        HRESULT MoveFirst();
        HRESULT MoveLast();

        bool Get(char* FieldName, char* FieldValue);
        bool Get(char* FieldName,SYSTEMTIME& FieldValue);
        bool Get(char* FieldName,float& FieldValue);
        bool Get(char* FieldName,double& FieldValue);
        bool Get(char* FieldName,double& FieldValue,int Scale);
        bool Get(char* FieldName,long& FieldValue);

    BOOL VariantTimeToSystemTimeWithMilliseconds (/*input*/ double
dVariantTime, /*output*/SYSTEMTIME *st);



};- Hide quoted text -

- Show quoted text -

Hi

Accoerding to code, I believe, you just need to declare forward class
Table. because 1. you used the name of Table before its declaration
and 2. because you used the reference (or pointer) to Table rather
than plain Table. Consider:

// 1
class Y;
class X {
public:
X(const Y&); // ok
void f(Y*); // ok
};

class Y {
/* ... */
};

// 2
class Y;
class X {
public:
X(const Y); // error: use of undefined type Y
};

class Y {
};

Regards,
S. Amrollahi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top