when declaring:
andCode:Account nAcnt1;
the latter is a pointer to Account class.Code:Account *nAcnt2;
but if we go:
what do u call this new type?Code:nAcnt2=new Account;
when declaring:
andCode:Account nAcnt1;
the latter is a pointer to Account class.Code:Account *nAcnt2;
but if we go:
what do u call this new type?Code:nAcnt2=new Account;
We call it
"A pointer pointing to a dynamicaly allocated object of an 'Account' class."
Yes I'm trying to confuse you.
Nope, the latter is a pointer to an Account object. None exists at the (uninitialized) location it's pointing at.Originally Posted by hoangvo
nAcnt2 is still a pointer to an Account object. Its type won't change. This time an Account object exists at the location it's pointing at.Originally Posted by hoangvo
Pointers are variables that store addresses. With this statement:
Account *nAcnt2;
you create a pointer variable called nAcnt2, which you have declared will store the address of an Account object. I prefer to use this format:
Account* nAcnt2;
That format makes it clear the variable name is 'nAcnt2', and the type is Account*.
The 'new' keyword dynamically creates an object and returns its address in memory. So, here:
nAcnt2=new Account;
you create an Account object, and assign its address to the variable nAcnt2.
Last edited by 7stud; 07-24-2005 at 12:19 PM.
Declares a pointer to a. You can access a as a or *p.Code:Account a; Account *p = &a;
Declares a pointer to a newly allocated Account. But in this case, the only way you can access this Account is through *p.Code:Account *p = new Account;
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.