Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help and explanation on Pointers.

Status
Not open for further replies.

MindCracker

Programmer
Aug 27, 2002
21
0
0
GB
Hi

I am learning Visual C++ and struggling to understand what they means:
1) What is CMainFrame *mainframe = (CMainFrame *) AfxGetMainWnd();
2) mainframe->ProgressAddString(ctext);
3) What is the difference between CMainFrame *mainframe and CMainFrame* mainframe? Are they the same?? Which one is the correct way?

Can anyone please help to explain that? I read many programming boooks but still got to nowhere. Any recommended resources I could refer to ? Please help!! Thank you
 
Hi,

I will start from point 3.

3) they are the same; in both case, mainframe is a pointer
to an object of CMainFrame class.
The problems become when you write more than a variable in
one declaration.
Try to write a part of program that analyze the sizeof of:

CMainFrame p0 ;
CMainFrame *p1 ;
CMainFrame* p2 ;
CMainFrame *p3, *p4, p5 ;
CMainFrame* p6, p7 ;


2) Here, you simply run a function: it is a member
of the object pointed by mainframe.

1) The operator (something) is called "cast". Often,
in C++, this is only a formal problem:
mainframe and the return value of AfxGetMainWnd,
are both pointers ( 4 byte here, now ), but in the
declaration are one to CMainFrame and the other to CWnd:
whit this cast you take the responsability to put
a type in an other.

In old version of C, you can write:

int i1, *i2 ;

i1 = 5 ;
i2 = i1 ;

whithout receive error ( at compile time! ) ;


Bye
 
Dear Victor,

Thanks very much for your help. Your explanation is very clear and helpful!!! I finally got the point. Have a good day to you!

cheers,

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top