Click here to Skip to main content
15,877,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to know the difference between:
C++
classname obj;
classname* obj;

How and when to use the above two?
Posted
Updated 15-Dec-10 19:29pm
v2

Hi,

classname obj;

obj is and object of class classname, Where as in (classname* obj) obj is pointer to an object of class classname.

You can refer this article to know more.

http://msdn.microsoft.com/en-us/library/e1t5f7bs.aspx

[^]
 
Share this answer
 
You don't seem to know what is a pointer, so I sincerely doubt any of the online forums are going to be useful to you.

Please read a good book on C. Once you understand the basics, online forums will be of great help to you.
 
Share this answer
 
v2
Comments
CPallini 16-Dec-10 3:36am    
God call.
Dalek Dave 16-Dec-10 4:28am    
Harsh but fair! :)
tgpai 17-Dec-10 3:32am    
ok!! thanks.
classname object;
classname* pointer_object;
object.member_function();
pointer_object->member_function();
pointer_object[0].member_function();
pointer_object[10].member_function(); // if pointer_object is an array of classname
 
Share this answer
 
v2
Comments
[no name] 16-Dec-10 15:10pm    
Also (*pointer_object).member_function();
[no name] 17-Dec-10 8:03am    
pointer_object = new classname();

// ...

if(pointer_object!=NULL)
{
delete pointer_object;
}

pointer_object = new classname[100]();

// ...

if(pointer_object!=NULL)
{
delete []pointer_object;
}
First understand the concept of pointer and than click here for more information ->[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900