|
downcast or upcast? A is at higher level in hierarchy.
|
|
|
|
|
aesthetic.crazy wrote: downcast or upcast?
You are casting from a derived class to a base class, and in English base is considered the lowest level, thus downcasting. I agree it's difficult because most diagrams give the impression that A (the base class) is at the top of the hierarchy.
I must get a clever new signature for 2011.
|
|
|
|
|
The type of the pointer is determined by the left hand side of the expression. The type of the created object is determined by the right hand side of the expression.
One interesting thing about C++ and C (to a lesser extent) is that when you declare a pointer you're not saying "this variable is a pointer to fixed class" but you're saying "this variable is a pointer to something with an interface of this type." In c this really only shows up when you convert to and from void * but in C++ it crops up a lot more (it's how C++ implements substitutability, AKA the Liskov Principle).
From this lot, when you write the expression:
A *p = new B;
you're saying two things to the compiler "p is a pointer to something with the interface of A" and "initialise that pointer with the address of a dynamically allocated B."
Cheers,
Ash
|
|
|
|
|
Some answers should have a "Really Good Answer" button.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Hi all i have developed a MFC Dialoag based application (server application TCP/IP communication a socket programming) on windows xp sp2.
I am getting application error message on one of the machine. but some other machine it is working fine. I am not able to fix this bug please help me .
The Error message is:
The instruction at "0x7c911948" referenced memory at "0x00000000".The memory could not be "read",
click on OK to terminate the program
click on CANCEL to debug the program
What error it is and how to fix it ?
Thanks in advance
|
|
|
|
|
It means your app tried to access memory using a null pointer.
To fix: Run your app under the debugger, check the call stack when it breaks.
|
|
|
|
|
how to check the call stack.
|
|
|
|
|
Should be down the bottom, but you can activate it via Debug>Windows>Call Stack
|
|
|
|
|
i am using vc++ 6.0
i am not able to get this option Debug>Windows>Call Stack
|
|
|
|
|
View > Debug Windows > Call Stack
|
|
|
|
|
A call stack is the bare minimum.
Steve
|
|
|
|
|
The other way out is click on 'CANCEL' button to debug.
Before that copy the source code on the machine where you get the above crash.
Open the project in visual studio and build the project in 'DEBUG' mode.
Now run the application and click 'CANCEL' button to debug when the above error occurs.
When OS asks for debugger to attache, provide the running instance of the visual studio, that will take you to the point where the access violation is raised.
|
|
|
|
|
this error because i am creating multiple thread using AfxBeginThread() see below
my code :
WSADATA wsaData;
WSAStartup(0x0101, &wsaData );
struct sockaddr_in stSockaddr_in;
struct sockaddr stSockaddr;
SOCKET sock;
fd_set readfds1;
FD_ZERO( &readfds1);
//create listening socket
sock = socket(AF_INET,SOCK_STREAM,0);//create socket
//sets the family,port and the addrees
stSockaddr_in.sin_family = AF_INET;
stSockaddr_in.sin_addr.s_addr = INADDR_ANY;
stSockaddr_in.sin_port = htons(9000)
//Use bind to establish the local association of the socket by assigning a local name to an unnamed socket
int nRet = bind(sock, (LPSOCKADDR)&stSockaddr_in, sizeof(struct sockaddr));//bind
//listen function places a socket a state where it is listening for an incoming connection
if(listen( sock, MAX_CONNECTS ) < 0)//listen
{
//listen error
return 0;
}
SOCKET ret_sock;
//accept the connection
ret_sock = accept(sock,&stSockaddr,NULL);
if(INVALID_SOCKET != ret_sock)
{
char szBuffer[MAX_BUF_LEN];
//to receive the configuration data
int iLength = recv( ret_sock,(char*) szBuffer, MAX_BUF_LEN, 0 );
szBuffer[iLength] = 0;
CString csBuffer;
int iLen = strlen(szBuffer);
WCHAR wcStr[MAX_DATA_SIZE];
memset(wcStr,'\0',sizeof(WCHAR)*MAX_DATA_SIZE);
mbstowcs( wcStr,szBuffer,iLen);
csBuffer.Format(L"%s",wcStr);
////////////////////////////////////////////////////////////////////////
if(!csBuffer.IsEmpty())//data is not empty
{
CWinThread *Thread = NULL;
Thread = AfxBeginThread(func,(LPVOID)&someValue,THREAD_PRIORITY_NORMAL,0,0,NULL); //Here only i am getting the apllication error (Not Creating Multiple thead)
}
}
How to resolve this problem ?
|
|
|
|
|
To fix: Run your app under the debugger, check the call stack when it breaks.
|
|
|
|
|
it breaks in afxBeginthread creation only?
|
|
|
|
|
Why does it break?
What source line does it break on? What module?
If it breaks because of an assert, what does the assert statement say?
If it breaks because of a null pointer, what is the pointer supposed to be pointing to?
How do you expect us to help you when you don't give us all the details?
|
|
|
|
|
i have created parent thread,
AfxBeginThread(parent,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
declaration :
class CTestApp : public CWinApp
{
public:
static UINT parent(LPVOID lpParam);
static UINT child(LPVOID lpParam);
/////////////////////////////////////////////////////////////////////////////
definition:
UINT CTestApp::parent(LPVOID lpParam) //multiple client request the parent
{
//.....
//listening socket and create new thread
if(!csBuffer.IsEmpty())//data is not empty
{
CWinThread *Thread = NULL;
Thread = AfxBeginThread(child,(LPVOID)&someValue,THREAD_PRIORITY_NORMAL,0,0,NULL); //Here only i am getting the apllication error (Not Creating Multiple thead)
}
return 1;
}
UINT CTestApp::child(LPVOID lpParam) //mulitple times its has to created
{
//do stuff
return 1;
}
i hope this time i have given clearly my problem. I am tryng to create a multiple threads
-- Modified Monday, January 24, 2011 11:08 AM
|
|
|
|
|
So have you stepped into AfxBeginThread() to see what is going on?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi all,
i have an edit box,when i paste some data of diffrent laguage like chines its correctly visible on dialog box.
but i m GetDlgItemText this value here all values ar display in ???????? this format.
please tell me how can i get same value after GetDlgItemText in application.
thanks in advance
|
|
|
|
|
This is most likely due to you only using the ASCII character set.
You need to select "Use Unicode Character Set" from the Project Properties>General>Character Set
|
|
|
|
|
there is any other option that work for it with Multi byte character set option.
|
|
|
|
|
Absolutely. I prefer Unicode because it is easier to work with.
|
|
|
|
|
actually i worked with multibyte and if now i change it there is so many error comes.
|
|
|
|
|
If you are not changing your application to unicode than use
GetDlgItemTextW and CStringW.
May be this will solve your problem.
I believe in LOVE AT FIRST SITE...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
Hi There,
Recently I'm trying allegro game programming library. I wanted to implement a multi-threaded program using allegro. But when I try to compile it, it give me an error "conflicting declaration 'typedef struct tagBITMAP BITMAP'". When I remove the Header file windows.h, this error message is not displayed. So that mean I can't use windows.h and allegro.h same time.
Please give me a comment regarding this problem.
Thank you verymuch
Thil
|
|
|
|