operator overloading
-
Here is my problem! I have three classes set up sort of like this: class MainClass { CSocketClass * pSock; // instance of my socket class. } class CSocketClass { CSocketAddr * pObj; }; class CSocketAddr { operator LPSOCKADDR() { return ( LPSOCKADDR )( LPSOCKADDR_IN )this; } } When I call my MainObject->pSock->bind() [which uses my LPSOCKADDR override] and try to do some binding, the pointer this does not refer to the class I called it from, it points back to my main object! That is bunk! When I say "this" I want the class I am calling in. Is it just me? Peace. ---- Xian
-
Here is my problem! I have three classes set up sort of like this: class MainClass { CSocketClass * pSock; // instance of my socket class. } class CSocketClass { CSocketAddr * pObj; }; class CSocketAddr { operator LPSOCKADDR() { return ( LPSOCKADDR )( LPSOCKADDR_IN )this; } } When I call my MainObject->pSock->bind() [which uses my LPSOCKADDR override] and try to do some binding, the pointer this does not refer to the class I called it from, it points back to my main object! That is bunk! When I say "this" I want the class I am calling in. Is it just me? Peace. ---- Xian
What does you bind function look like?
Todd Smith
-
What does you bind function look like?
Todd Smith
void XSocket::bindAddress()
{
if( ::bind( m_hSocket, ( LPSOCKADDR )m_pAddress, sizeof( SOCKADDR ) ) == SOCKET_ERROR )
throw "bindAddress";
}Well, not anymore...:-D I got around this by not overloading operators and calling member funcs explicitly. It still p1ss3s me off though! I think the "this" pointer within a class should reference the class it is within. Peace. ---- Xian