473,396 Members | 1,789 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,396 software developers and data experts.

C++ syntax doubts

18
consider the code given below:

class base { //line1
private: //line2
const int a; //line3

public: //line4
base(int val = 0) : a(val) {} //line5
int get_a() { return a; }
}; // C4512 warning

class base2 {
private:
const int a;

public:
base2(int val = 0) : a(val) {}
base2 & operator=( const base2 & ) {}
int get_a() { return a; }
};

int main() {
base first;
base second;

// OK
base2 first2;
base2 second2;
}


What does the 'line5' signify?..I think ':' operator is for deriving a class from base class. But what is it doing for a method? I really could not understand .Can anyone help me???
Feb 7 '07 #1
2 1394
consider the code given below:

class base { //line1
private: //line2
const int a; //line3

public: //line4
base(int val = 0) : a(val) {} //line5
int get_a() { return a; }
}; // C4512 warning

class base2 {
private:
const int a;

public:
base2(int val = 0) : a(val) {}
base2 & operator=( const base2 & ) {}
int get_a() { return a; }
};

int main() {
base first;
base second;

// OK
base2 first2;
base2 second2;
}


What does the 'line5' signify?..I think ':' operator is for deriving a class from base class. But what is it doing for a method? I really could not understand .Can anyone help me???


STATEMENTS COMING AFTER // IS USER FRIENDLY COMMENTS......
Feb 7 '07 #2
horace1
1,510 Expert 1GB
this is a constructor
Expand|Select|Wrap|Line Numbers
  1. base(int val = 0) : a(val) {} //line5
where : a(val) is an initialisation list which initialises the data member a to the value of parameter val (which will default to 0 if non is supplied) see
http://www.cprogramming.com/tutorial/initialization-lists-c++.html
Feb 7 '07 #3

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
0
by: abbas reji | last post by:
--0-599929911-1059996886=:4358 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Id: Content-Disposition: inline ...
1
by: Piotre Ugrumov | last post by:
I have some problems and some doubts. I have implemented a class hierachy. The base class Velivolo, from Velivolo derive Militare and Civile, from militare derive Aereo and Elicottero, from Civile...
6
by: Christopher Benson-Manica | last post by:
I presume that putting the default case of a switch statement before the others is legal, as in the following skeleton program: #include <stdio.h> int main( int argc, char *argv ) { switch(...
6
by: ritesh | last post by:
Hi, I have been reading some text on C and C++ (i.e advanced books). One of the books mentioned that C++ requires a runtime support whereas C does not - what the author was trying to say was...
17
by: ranjeet.gupta | last post by:
Dear All Below are the few doubts which I got while studying about C 1. Is there any method in C by which we can process the entire string in one unit, 2. Does there exist any way to...
13
by: maadhuu | last post by:
hello everybody, i have 2 doubts . 1. is this always defined ?? int i =10; int a = i++ + i++; and also, i tried this in gcc, answer was 20, so what the sequence points for evaluation of...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
1
by: NagaKiran | last post by:
Hi I want to post VBA related doubts. Where can I post my doubts in VBA? thanks bye
19
by: Ingo Linkweiler | last post by:
Has anyone a function/script to verify an e-mail-address? It should: a) check the syntax b) verify an existing mailserver or DNS/MX records ingo
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.