c/ c++ struct question

Hi I need to convert some c++ code so that it runs on an iPhone (objectve c).
I have the following struct in C++ format:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
struct tagMessage
{
	 //tagMessage(const char* MsgBuffer, long lMsgLen ) :
	 struct tagMessage(char* MsgBuffer, long lMsgLen ) :
		m_pMsg(NULL),
		m_lMsgLen(0)
		{
		   if(lMsgLen)
		   {
			ASSERT(MsgBuffer);
			m_pMsg = new char[lMsgLen + TAG_LEN];
			memcpy(m_pMsg,	BEGIN_TAG,	BEGIN_TAG_LEN);
			memcpy(&m_pMsg[LEN_POS],&lMsgLen,sizeof(long));
			memcpy(&m_pMsg[MSG_POS],MsgBuffer,lMsgLen);
			memcpy(&m_pMsg[END_POS(lMsgLen)],END_TAG, END_TAG_LEN);

			m_lMsgLen = lMsgLen + TAG_LEN;
		   }	
		}

	~tagMessage()
		{
		   if(m_pMsg)
		      delete [] m_pMsg;
		}

	long	m_lMsgLen;		// Message len
	char*   m_pMsg ;		// Message Data
};


As you see this has a constructor and a destructor.

Now is it true that 'c' does not support Structures having constructors and destructors??

So is the only way I can get around this problem is to have a separate function that simply initialises the structures variables?
C doesn't support structures having methods at all, including constructors and destructors. Your idea is fine; just make external functions that take a pointer to an instance to work as the "this" pointer.
Topic archived. No new replies allowed.