|
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.
|
|
|
|
|
Hello,
does anybody know how to convert char** to char array?
here is my code
<br />
#include stdio.h<br />
<br />
splitString(char** aString)<br />
{<br />
char[10][10] localstring;<br />
.....<br />
.....<br />
.....<br />
<br />
.....<br />
<br />
}<br />
<br />
int main<br />
{<br />
char[10][10] arraystring;<br />
splitString(arraystring);<br />
return 0;<br />
}<br />
Thanks
It is never late to learn
|
|
|
|
|
You can't!
See the Section 2.10[^].
Maxwell Chen
|
|
|
|
|
Hello,
thanks for your reply.
I think i can,
here is what i did
<br />
memcpy(localstring,aString, sizeof(localstring));<br />
But, I want localstring to point aString's address.
<br />
It is easy if<br />
char *aString, then address of aString -> &aString,<br />
if it is<br />
char **aString, then address of aString -> ??????<br />
that is the problem i dont know.
How do we get aString's address?
thanks
It is never late to learn
|
|
|
|
|
splitString(char localstring[][10])
{
.....
.....
Is it acceptable?
|
|
|
|
|
Hello,
thanks for your reply.
But it is not acceptable,
Because sometimes
i call splitString() function with char** parametr.
thanks
It is never late to learn
|
|
|
|
|
Gofur Halmurat wrote: i call splitString() function with char** parametr.
with char**, you mean simply typecast type of multidimentional array of characters or array of pointers to array. Both cannot be interchanged.
char aString[10][10] = {"Test1", "Test2", "Test3"};
char *aString2[10] = {"Test1", "Test2", "Test3"};
former uses contigious buffer while later stores pointers to some other location. So you have to be sure what kind of data the function expects.
in your example any way you can type cast like this.
char (*localString)[10][10];
localString = reinterpret_cast<char (*)[10][10]>(aString); note astring should be a multidimentional array as in your example.
if you are really expecting the muldimensional array, restrict the user by using the array in function argument.
|
|
|
|