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;
Printable View
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.Quote:
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.Quote:
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.
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;