Sign in to follow this  
hkBattousai

[SOLVED] ERROR: aggregate CMessage message' has incomplete type and cannot be defined

Recommended Posts

I have written a class named CMessage in order to hold text messages (titles & bodies). When I link this class to the main source code, but not define an object with it, I don't get any warning or error message. But when a define an object CMessage message; I get an error like this :
Quote:
23 C:\Prog\SAVE\wxDevCPP\CWMS\Modules\wndNewMessage.h aggregate `CMessage message' has incomplete type and cannot be defined
What's wrong my code? I got stuck with this error. Any help or suggestion will be greatly appreciated. My platform is : WinXP Home wxDevCPP Source code of the class :
class CMessage
{
	private:
		int GetNumOfSpecialCharacters(char * szString);
		int String2HTML(char * szStr, char * szOut);
		int HTML2String(char * szStr, char * szOut);

	public:
		char * szEncodedTitle;
		char * szRawTitle;
		char * szEncodedBody;
		char * szRawBody;
		//int nNumUsers;
		char szDeadLine[20];
		char szCurrentDATETIME[20];

		~CMessage();

		void SetRawTitle(char * szRawTitle, int nLength);
		int GetRawTitleLength(void);
		void GetRawTitle(char * szRawTitle);
		int GetEncodedTitleLength(void);
		void GetEncodedTitle(char * szEncodedTitle);

		void SetRawBody(char * szRawBody, int nLength)
		int GetRawBodyLength(void);
		void GetRawBody(char * szRawBody);
		int GetEncodedBodyLength(void);
		void GetEncodedBody(char * szEncodedBody);

		//void SetNumberOfUsers(int nNumUsers);
		void static MakeDATETIME(	UINT uiYear, UINT uiMonth, UINT uiDay,
							UINT uiHour, UINT uiMinute, UINT uiSeconds, char * szDEADTIME);
		void SetCurrentDATETIME(void);
		void SetDeadLine(	UINT uiYear, UINT uiMonth, UINT uiDay,
							UINT uiHour, UINT uiMinute, UINT uiSeconds);
		//void Send(void);
};

CMessage::~CMessage()
{
	delete szRawTitle;
	delete szEncodedTitle;
	delete szRawBody;
	delete szEncodedBody;
}

/*		SetRawTitle()
	This function stores string values for both encoded and raw titles.
*/
void CMessage::SetRawTitle(char * szRawTitle, int nLength)
{
	strcpy(this->szRawTitle, szRawTitle);
	this->szEncodedTitle = new char[nLength + 4 * this->GetNumOfSpecialCharacters(szRawTitle) + 1];
	this->String2HTML(this->szRawTitle, this->szEncodedTitle);
}

/*		GetRawTitleLength()
	Returns the length of the raw title.
*/
int CMessage::GetRawTitleLength(void)
{
	return (int) strlen(this->szRawTitle);
}

/*		GetRawTitle()
	Returns the raw title of the message.
	Main program must call GetRawTitleLength() and allocate enough space first.
*/
void CMessage::GetRawTitle(char * szRawTitle)
{
	this->HTML2String(szRawTitle, this->szRawTitle);
}

/*		GetEncodedTitleLength()
	Returns the length of the encoded title.
*/
int CMessage::GetEncodedTitleLength(void)
{
	return (int) strlen(this->szEncodedTitle);
}

/*		GetEncodedTitle()
	Returns the raw title of the message.
	Main program must call GetRawTitleLength() and allocate enough space first.
*/
void CMessage::GetRawTitle(char * szRawTitle)
{
	this->HTML2String(szRawTitle, this->szRawTitle);
}

/*		SetRawBody()
	This function stores string values for both encoded and raw bodies.
*/
void CMessage::SetRawBody(char * szRawBody, int nLength)
{
	strcpy(this->szRawBody, szRawBody);
	this->szEncodedBody = new char[nLength + 4 * this->GetNumOfSpecialCharacters(szRawBody) + 1];
	this->String2HTML(this->szRawBody, this->szEncodedBody);
}

/*		GetRawBodyLength()
	Returns the length of the raw body.
*/
int CMessage::GetRawBodyLength(void)
{
	return (int) strlen(this->szRawBody);
}

/*		GetRawBody()
	Returns the raw body of the message.
	Main program must call GetRawBodyLength() and allocate enough space first.
*/
void CMessage::GetRawBody(char * szRawBody)
{
	this->HTML2String(szRawBody, this->szRawBody);
}

/*		GetEncodedBodyLength()
	Returns the length of the encoded body.
*/
int CMessage::GetEncodedBodyLength(void)
{
	return (int) strlen(this->szEncodedBody);
}

/*		GetEncodedBody()
	Returns the raw body of the message.
	Main program must call GetRawBodyLength() and allocate enough space first.
*/
void CMessage::GetRawBody(char * szRawBody)
{
	this->HTML2String(szRawBody, this->szRawBody);
}

/*		MakeDATETIME()
	This is static method of this class which is used to build a
	DATETIME string to be used in MySQL database. The string is
	returned in the last parameter.
*/
void static CMessage::MakeDATETIME(UINT uiYear, UINT uiMonth, UINT uiDay,
							UINT uiHour, UINT uiMinute, UINT uiSeconds, char * szDEADTIME)
{
	szDEADTIME[0]  = (char) ((int) ((uiYear   / 1000) % 10) + 48);
	szDEADTIME[1]  = (char) ((int) ((uiYear   / 100)  % 10) + 48);
	szDEADTIME[2]  = (char) ((int) ((uiYear   / 10)   % 10) + 48);
	szDEADTIME[3]  = (char) ((int) ((uiYear   / 1)    % 10) + 48);
	szDEADTIME[4]  = '-';
	szDEADTIME[5]  = (char) ((int) ((uiMonth  / 10)   % 10) + 48);
	szDEADTIME[6]  = (char) ((int) ((uiMonth  / 1)    % 10) + 48);
	szDEADTIME[7]  = '-';
	szDEADTIME[8]  = (char) ((int) ((uiDay    / 10)   % 10) + 48);
	szDEADTIME[9]  = (char) ((int) ((uiDay    / 1)    % 10) + 48);
	szDEADTIME[10] = ' ';
	szDEADTIME[11] = (char) ((int) ((uiHour   / 10)   % 10) + 48);
	szDEADTIME[12] = (char) ((int) ((uiHour   / 1)    % 10) + 48);
	szDEADTIME[13] = ':';
	szDEADTIME[14] = (char) ((int) ((uiMinute / 10)   % 10) + 48);
	szDEADTIME[15] = (char) ((int) ((uiMinute / 1)    % 10) + 48);
	szDEADTIME[16] = ':';
	szDEADTIME[17] = (char) ((int) ((uiSecond / 10)   % 10) + 48);
	szDEADTIME[18] = (char) ((int) ((uiSecond / 1)    % 10) + 48);
	szDEADTIME[19] = (char) 0;
}

/*		SetCurrentDATETIME()
	This method is called once just before the message is post to the database.
	It prepares the szCurrentDATETIME member of this class.
*/
void CMessage::SetCurrentDATETIME(void)
{
	SYSTEMTIME st;
	GetLocalTime(&st);

	this->MakeDATETIME(	st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute,
						(UINT) 0, this->CurrentDATETIME);
}

/*		SetDeadLine()
	This method is called to modify the "szDeadLine" member of this class
*/
void CMessage::SetDeadLine(	UINT uiYear, UINT uiMonth, UINT uiDay,
							UINT uiHour, UINT uiMinute, UINT uiSeconds);
{
	this->MakeDATETIME(	uiYear, uiMonth, uiDay, uiHour, uiMinute,
						(UINT) 0, this->szDeadLine);
}

//void CMessage::Send(void)
//{
//
//}

int CMessage::String2HTML(char * szStr, char * szOut)
{
	// CONVERSION MAPPING TABLE
	// 0x08 ==  8 == \b == backspace
	// 0x09 ==  9 == \t == tab
	// 0x0A == 10 == \n == new line
	// 0x0C == 12 == \f == paper feed
	// 0x0D == 13 == \r == cariage return
	// 0x22 == 34 == \" == double quote
	// 0x23 == 35 == \# == hash mark
	// 0x26 == 38 == \& == ampersand
	// 0x27 == 39 == \' == single quote
	// 0x3B == 59 == \; == semicolon
	// 0x5C == 92 == \\ == backslash
	int nLen = strlen(szStr);
	int j=0;

	for (int i=0; i<nLen; i++)
		switch ((int) szStr[i])
		{
			case 8:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '0'; j++;
				szOut[i+j] = '8'; j++;
				szOut[i+j] = ';';
				break;
			case 9:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '0'; j++;
				szOut[i+j] = '9'; j++;
				szOut[i+j] = ';';
				break;
			case 10:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '1'; j++;
				szOut[i+j] = '0'; j++;
				szOut[i+j] = ';';
				break;
			case 12:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '1'; j++;
				szOut[i+j] = '2'; j++;
				szOut[i+j] = ';';
				break;
			case 13:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '1'; j++;
				szOut[i+j] = '3'; j++;
				szOut[i+j] = ';';
				break;
			case 34:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '3'; j++;
				szOut[i+j] = '4'; j++;
				szOut[i+j] = ';';
				break;
			case 35:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '3'; j++;
				szOut[i+j] = '5'; j++;
				szOut[i+j] = ';';
				break;
			case 38:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '3'; j++;
				szOut[i+j] = '8'; j++;
				szOut[i+j] = ';';
				break;
			case 39:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '3'; j++;
				szOut[i+j] = '9'; j++;
				szOut[i+j] = ';';
				break;
			case 59:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '5'; j++;
				szOut[i+j] = '9'; j++;
				szOut[i+j] = ';';
				break;
			case 92:
				szOut[i+j] = '&'; j++;
				szOut[i+j] = '#'; j++;
				szOut[i+j] = '9'; j++;
				szOut[i+j] = '2'; j++;
				szOut[i+j] = ';';
				break;
			default:						// otherwise
				szOut[i+j] = szStr[i];
		}

	szOut[nLen + j] = (char) 0x00;

	return nLen + j;
}
int CMessage::HTML2String(char * szStr, char * szOut)
{
	// CONVERSION MAPPING TABLE
	// 0x08 ==  8 == \b == backspace
	// 0x09 ==  9 == \t == tab
	// 0x0A == 10 == \n == new line
	// 0x0C == 12 == \f == paper feed
	// 0x0D == 13 == \r == cariage return
	// 0x22 == 34 == \" == double quote
	// 0x23 == 35 == \# == hash mark
	// 0x26 == 38 == \& == ampersand
	// 0x27 == 39 == \' == single quote
	// 0x3B == 59 == \; == semicolon
	// 0x5C == 92 == \\ == backslash
	int nLen = strlen(szStr);
	int j=0;

	for (int i=0; i<nLen; i++)
	{
		if (szStr[i+0] == (char) 0x26)				// & character
  		{
	   	    int nCode = ((int) szStr[i+2] - 48) * 10 + ((int) szStr[i+3] - 48);
	   	    if (	(szStr[i+1] == (char) 0x23)		// # character
				&&	(szStr[i+2] <= '9')
				&&	(szStr[i+2] >= '0')
				&&	(szStr[i+3] <= '9')
				&&	(szStr[i+3] >= '0')
				&&	(szStr[i+4] == (char) 0x3B))	// ; character
			{
				szOut[i + j] = (char) nCode;
				j--; j--; j--; j--;					// faster than j-=4;
				i++; i++; i++; i++;
			}
		}
		else
		{
			szOut[i + j] = szStr[i];
		}
	}

	szOut[nLen + j] = (char) 0x00;

	return nLen + j;
}

int CMessage::GetNumOfSpecialCharacters(char * szString)
{
	// CONVERSION MAPPING TABLE
	// 0x08 ==  8 == \b == backspace
	// 0x09 ==  9 == \t == tab
	// 0x0A == 10 == \n == new line
	// 0x0C == 12 == \f == paper feed
	// 0x0D == 13 == \r == cariage return
	// 0x22 == 34 == \" == double quote
	// 0x23 == 35 == \# == hash mark
	// 0x26 == 38 == \& == ampersand
	// 0x27 == 39 == \' == single quote
	// 0x3B == 59 == \; == semicolon
	// 0x5C == 92 == \\ == backslash
	int nLen = strlen(szString);
	int nSpc = 0;
	for (int i=0; i<nLen; i++)
		if ((szString[i] == (char)  8)	||
			(szString[i] == (char)  9)	||
			(szString[i] == (char) 10)	||
			(szString[i] == (char) 12)	||
			(szString[i] == (char) 13)	||
			(szString[i] == (char) 34)	||
			(szString[i] == (char) 35)	||
			(szString[i] == (char) 38)	||
			(szString[i] == (char) 39)	||
			(szString[i] == (char) 59)	||
			(szString[i] == (char) 92))			nSpc++;
	return nSpc;
}

[Edited by - Battousai on February 18, 2008 7:09:36 AM]

Share this post


Link to post
Share on other sites
Looks to me like wndNewMessage.h doesn't #include the header that CMessage is defined in, or if it does, you have a circular dependancy. That error looks like you've just declared CMessage as:
class CMessage;
in wndNewMessage.h, and to derive a class you require the full declaration of the class to be visible.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Looks to me like wndNewMessage.h doesn't #include the header that CMessage is defined in, or if it does, you have a circular dependancy. That error looks like you've just declared CMessage as:
class CMessage;
in wndNewMessage.h, and to derive a class you require the full declaration of the class to be visible.


Thank you Steve. The problem was just like you said. I had made the symbolic declaration of CMessage in a different file but didn't include its code to the project.

The problem is solved.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this