* Hakirato:
Hi
I have this compilation problem when trying to convert C code to C++.
My function looks like this:
void FTPServer_ThreadLoop( void *arg_p )
{
FTPSettings_t* FTPSettings_p;
FTPSettings_p = arg_p;
..
..
..
}
typedef struct
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;
} FTPSettings_t;
When I compile I have this problem:
error C2440: '=' : cannot convert from 'void *' to 'FTPSettings_t *'
Conversion from 'void*' to pointer to non-'void' requires an
explicit cast
Please help me how to solve this problem. Thanks
One purely technical answer is:
void FTPServer_ThreadLoop_C( void* pSettings )
{
FTPServer_ThreadLoop( *static_cast<FTPSettings*>( pSettings ) );
}
which calls the following more type safe function:
void FTPServer_ThreadLoop( FTPSettings& settings )
{
...
}
Given that, for maintainability it can be a good idea to do something like
struct FTPState
{
FTPState_t State;
SOCKADDR_STORAGE sa;
SOCKADDRLEN salen;
SOCKET sock;
void ThreadLoop()
{
...
}
};
namespace g
{
FTPState* pFtpState; // Managed by code not shown here.
}
void FTPServer_ThreadLoop( FTPSettings& settings )
{
g::pFtpState->ThreadLoop();
}
and then notice that there's probably initialization (which should be a
constructor), destruction (which should be a destructor), and matters of
access to be granted or restricted, and so on.
Actually I wouldn't use the namespace as shown above, and in fact the
code wouldn't resemble this at all. <g I'm trying to write something
you'd find at least slightly familiar. Hope this helps.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?