By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

doubt not going on : operator

P: 11
Hi I have the following code:

Expand|Select|Wrap|Line Numbers
  1. struct Point
  2. {
  3.     double x, y;
  4.  
  5.     inline Point(double X = 0, double Y = 0) : x(X), y(Y){ }       
  6. };
  7.  
  8. can anybody clue WHY after " ) " , the programmer has used  : and in braces { } no code is wriiten.
  9. does he mean to make abstract class . or abstract structure?
  10. Consequently he has taken this example carried forward to make segment class using Point studture where he makes use of
  11.  
  12. class Segment
  13. {
  14. public:
  15.     inline Segment(const Point &a, const Point &b) : pointA(a), pointB(b){ }
  16.  
  17.          inline void setPointX(const Point &val) {pointA = val;}
  18.     inline void setPointY(const Point &val) {pointB = val;}
  19.  
  20. Private :
  21. Point pointA, point B
  22. }
  23.  
May i seek anybody help please.

Thanks and Regards,
Mack.
Mar 7 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
the : x(X), y(Y) in
Expand|Select|Wrap|Line Numbers
  1. struct Point
  2. {
  3.     double x, y;
  4.  
  5.     inline Point(double X = 0, double Y = 0) : x(X), y(Y){ }       
  6. };
  7.  
is an initialisation list to initialise the data member x and y, have a look at the tutorial
http://www.cprogramming.com/tutorial/initialization-lists-c++.html

in addition to other reasons it is more efficient than to use assignment, e.g.
Expand|Select|Wrap|Line Numbers
  1.   inline Point(double X = 0, double Y = 0) 
  2.        { x=X; y=Y; }       
  3.  
Mar 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.