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

Started by
3 comments, last by hkBattousai 16 years, 1 month ago
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)
		{
			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;
		}

	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 = (<span class="cpp-keyword">char</span>) nCode;
				j–; j–; j–; j–;					<span class="cpp-comment">// faster than j-=4;</span>
				i++; i++; i++; i++;
			}
		}
		<span class="cpp-keyword">else</span>
		{
			szOut = szStr<span style="font-weight:bold;">;
		}
	}

	szOut[nLen + j] = (<span class="cpp-keyword">char</span>) 0x00;

	<span class="cpp-keyword">return</span> nLen + j;
}

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

</pre></div><!–ENDSCRIPT–> 

<!–EDIT–><span class=editedby><!–/EDIT–>[Edited by - Battousai on February 18, 2008 7:09:36 AM]<!–EDIT–></span><!–/EDIT–>
Advertisement
i dont see a contructor in your class
Quote:Original post by ncsu121978
i dont see a contructor in your class


I've just added a constructor but it is still the same.
I don't think every class definition should contain a constructor, should it?
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.
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.

This topic is closed to new replies.

Advertisement