p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C++ Programming (http://p2p.wrox.com/forumdisplay.php?f=89)
-   -   c++ concepts (http://p2p.wrox.com/showthread.php?t=27919)

kerby April 10th, 2005 04:57 AM

c++ concepts
 
whats the difference of

 
Quote:

quote:SampleClass object;
Quote:


SampleClass *object;
in which SampleClass is a class.

further, what is the difference of

Code:

object.somefunction();
from...


Code:

object->somefunction();
a journey of a thousand miles is started by taking the first step -chinese proverb

Alan-LB April 10th, 2005 11:45 PM

Kerby

SampleClass object creates an object of "SampleClass" type
SampleClass *object creates a POINTER to an object of "SampleClass" type

object.somefunction() accesses "somefunction" within the object "object"
object->somefunction() dereferences a pointer to "object" to access "somefunction"

For you I think the "journey of a thousand miles" should start with the "first step" of carefully reading a few basic text books :-)

Read up on Objects and Pointers

Hope this helps

Alan


merediths April 16th, 2005 11:38 AM


 If you come from a C background think of it this way

 object->somefuntion();

 is the same as

 (*object).somefunction();

 this is, -> dereferences the pointer on the right and then calls it's somefunction() method.

Regards,
Meredith Shaebanyan


Alan-LB April 16th, 2005 11:39 PM

Which is what I said!

Alan



All times are GMT -4. The time now is 09:12 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.