Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Class member ac...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 9804 of 9984
Post > Topic >>

Class member acces through pointer vs object

by Rahul <rahulsharma@[EMAIL PROTECTED] > Jul 18, 2008 at 12:55 PM

{ Multi-posted to [comp.lang.c++]. -mod }

While reading Inside the C++ object model I came through the
following
paragraph

Point3d origin, *ptr = &origin;
A) origin.x = 0.0;
B) ptr->x = 0.0;

The book says "A & B statements performs equivalently if x is a
member
of a struct, class, single inheritance hierarchy, or multiple
inheritance hierarchy" This is because compiler knows the offset of
the member at compile time.

My doubt is, How can the  compiler know the offset of x in case of B
for multiple inheritance.
suppose we have
class Base_1{public: int i;}
class Base_2{public: int x;}
class Derived: public Base_1, public Base_2: {public: int k;}

now the offset of x will be different in Base_2 and Derived, and the
ptr may refer to any kind of object at run time, so how can we know
the offset at compile time.

I mean the access through pointer must be slower in the above case of
Multiple inheritance. Please correct me if I am wrong.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 5 Posts in Topic:
Class member acces through pointer vs object
Rahul <rahulsharma@[EM  2008-07-18 12:55:38 
Re: Class member acces through pointer vs object
Thomas Richter <thor@[  2008-07-18 15:05:22 
Re: Class member acces through pointer vs object
"Hakusa@[EMAIL PROTE  2008-07-18 15:06:18 
Re: Class member acces through pointer vs object
cbarron413@[EMAIL PROTECT  2008-07-19 14:35:21 
Re: Class member acces through pointer vs object
Alberto Ganesh Barbati &l  2008-07-19 14:40:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 8:44:00 CDT 2008.