473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

doubt not going on : operator

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
1 1393
horace1
1,510 Expert 1GB
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

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

Similar topics

6
by: praba kar | last post by:
Dear All, I have doubt regarding sorting. I have a list that list have another list (eg) list = ,,] I want to sort only numeric value having array field. How I need to do for that.
39
by: santosh | last post by:
Hello, I have two doubts on C++. 1. float i=1.1; double d=1.1; if(i==d) printf("equal\n"); else printf("not-equal\n"); what is the output? I am getting "not-equal" as output.
1
by: Srini | last post by:
I was reading the "Exceptional C++" of Herb Sutter. In an example, he mentions the following. // In some library header: namespace N { class C{}; } int operator+(int i, N::C) { return i+1; }...
4
by: Amit Bhatia | last post by:
Hi, I am trying to define the assignment operator for a class called Cell. I am bit confused between the following two statements: const Cell& Cell::operator=(const Cell &r) { \\ all the...
8
by: toton | last post by:
HI, One more small doubt from today's mail. I have certain function which returns a pointer (sometimes a const pointer from a const member function). And certain member function needs reference...
4
by: pradeep kaltari | last post by:
Hello friends, I have a doubt in the working of IN operator. I have a schema by name 'test_schema'. If you look at the following query the expected output is "1", but nothing is displayed. SELECT...
4
by: Deep | last post by:
I'm in doubt about what is smart pointer. so, please give me simple description about smart pointer and an example of that. I'm just novice in c++. regards, John.
8
by: naveen.dixit | last post by:
I have a piece of code #include<iostream> using namespace std; main() { int x=12; int *p = &x; cout<<endl<<p<<endl<<*p++<<endl; cout<<endl<<p<<endl<<*p<<endl;
11
by: subramanian100in | last post by:
In http://www.parashift.com/c++-faq-lite/friends.html#faq-14.5 the following is mentioned: (member functions don't allow promotion of the left hand argument, since that would change the...
5
by: nembo kid | last post by:
In the following function, s shouldn't be a pointer costant (array's name)? So why it is legal its increment? Thanks in advance. /* Code starts here */ void chartobyte (char *s) { while...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.