|
it's not a static function, nor a singleton.
it's just gonna crash because he deferences a NULL pointer...
|
|
|
|
|
Hi toxcct,
please check executing it. Are you getting exception?
And in the link provided in my orginal reply i explained my understanding.
toxcct wrote: it's not a static function, nor a singleton.
AFAIK, most singleton implementation tries to keep the object instance as one for process, but other than that, it is same as normal class instance. It should crash, if its corresponding normal instance crashes.
modified on Tuesday, March 11, 2008 10:06 AM
|
|
|
|
|
You need a compiler, my friend. Otherwise your teorethic point of view will sometimes clash with real world behaviours.
Of course, OP code was more than weird.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
probably something like :
"Segmentation Fault" or any other messages that pops up when you access an unallocated pointer or null pointer.
|
|
|
|
|
"You better pass to managed code."
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Why not try it and find out?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This is also funny !
class ABC
{
int m_i;
public:
void MyFunc() { _tprintf(_T("ABC %d", &m_i));}
void MyFunc2() { m_i = 3;}
};
int _tmain(int argc, _TCHAR* argv[])
{
ABC* c= NULL;
c->MyFunc(); // OK!
c->MyFunc2(); // ACCESS VIOLATION
return 0;
}
|
|
|
|
|
Really cannot you figure out that? See http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2456326[^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yes, but both methods use data member ...
|
|
|
|
|
Dieghito wrote: Yes, but both methods use data member ...
No.
MyFunc only takes the address of something which doesn't exist, which is also NULL (I guess, no compiler at home now). You can print any addresses including NULL .
If you change it as _tprintf(_T("ABC %d"), m_i) , it will crash.
Maxwell Chen
|
|
|
|
|
relate
[^]
and
[^]
&m_i = &* (this + offset of m_i) which is (this + offset of m_i) its not dereferencing and your printf format specifier is %d (0(this) + 0(offset of m_i)) is quite enough to work printf.
It is not accessing the value.
|
|
|
|
|
Actually, while the second really uses the data member, the first one use only the supposed address of the data member itself. Try a debugger session on the following code
class ABC
{
public:
int m_i;
int m_i2;
void MyFunc() { cout<<"hello atl";}
};
void main()
{
ABC *c= NULL;
int * p = &(c->m_i);
int * p2 = &(c->m_i2);
}
BTW I agree, we're on the funny (or weird, depending on taste) side of the things.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: BTW I agree, we're on the funny (or weird, depending on taste) side of the things.
Eight years ago, I wrote my ADO wrapper library at work. The whole thing was written in this taste.
ADOxxxClass* p = NULL;
p->SomeFunction(...);
Maxwell Chen
|
|
|
|
|
Maxwell Chen wrote: Eight years ago
wow, you are too experienced buddy.
|
|
|
|
|
Rajkumar R wrote: wow, you are too experienced buddy.
Maxwell Chen
|
|
|
|
|
Thanks.
|
|
|
|
|
Thank you, buddy!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hello everyone,
I can not find precise definition for typed argument for template and non-typed argument for template.
My understanding is,
code like
template <class T, int size> class Foo {
}
T is typed template argument, and size is non-typed template argument. My understanding correct?
thanks in advance,
George
|
|
|
|
|
|
Thanks Rajkumar,
Question answered.
regards,
George
|
|
|
|
|
I am to extract 1000's of records from database. since it takes quite some time I want play the avi file on the status bar of main frame, but the call will be made from the dialg. say on button click event I am extracting records form DB and need to play avi on the status bar, but ...
The instruction at "0x00402150" referenced memory at "0x00b9004c". The memory could not be "written".
void TestPb::OnButton1()
{
thpbar=AfxBeginThread(thPrgbar,THREAD_PRIORITY_NORMAL,0,0,NULL);
//Get 1000's records from DB ..verytime consumming process...
}
UINT TestPb::thPrgbar( LPVOID pParam )
{
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
pFrame->StartAnimation( IDR_AVITEST ,1);
return (1);
}
void CMainFrame::StartAnimation( UINT id, int nPane /*=1*/ )
{
StopAnimation();
m_pAnimate = new CStatusbarAnimate; // FLASHING ERROR
m_pAnimate->Create(id, nPane);
}
void CMainFrame::StopAnimation()
{
delete m_pAnimate;
m_pAnimate = NULL;
}
bool CMainFrame::IsAnimationActive()
{
return (m_pAnimate != NULL);
}
// needed to ensure original text not visible
void CMainFrame::OnUpdateAnimate(CCmdUI* pCmdUI)
{
pCmdUI->SetText(_T(""));
modified on Tuesday, March 11, 2008 8:29 AM
|
|
|
|
|
As you are stucking in this for a long time, i just looked in to the CStatusbarAnimate class.
Actually you don't need to start a thread to start the animation.
void TestPb::OnButton1()
{
// start animation here
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
pFrame->StartAnimation( IDR_AVITEST ,1);
thpbar=AfxBeginThread(thPrgbar,THREAD_PRIORITY_NORMAL,0,0,NULL);
}
UINT TestPb::thPrgbar( LPVOID pParam )
{
//Get 1000's records from DB ..verytime consumming process...
// just before returning you may post message to Main frame to stop the animation.
return (1);
}
void CMainFrame::OnStopAnimation()
{
StopAnimation();
}
|
|
|
|
|
Thanks you very much, Yes it is true. I really got strucked up here for a while... thanks for understanding my problem
I am modifying code of very large application, which has the same case number of times, so I looking for a simply way to do this, with out change much in the existing code, So I planed to have a thread that plays avi and call it when every required from all the dialog boxes...Am I going the right way...or is there any other work around...pls advice...
|
|
|
|
|
Have you tries as my suggestion?
|
|
|
|
|
ptr_Electron wrote: so I looking for a simply way to do this
I suggested only to add one statement of postmessage. And move your startanimation within the thread to before creating the thread which is in the button event, And its matter of 5 minutes. If this is not simple for you, then its difficult for you my friend.
|
|
|
|