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

??can u check this program...

20
#include<iostream.h>
class Room
{
int length;
int width;

public:
Room()
{}
Room(int l,int w=0) : width(w),length(l)
{
}
};

void main()
{
Room objRoom1;
Room obj2Room2(12,8);
}

This program is not giving any error.Now my question is : wat is the signifcance of this type of constructor declaration Room(int l,int w): width(w),legth(l)

y data member is defined as a function declaration and w and l as argument?
Note that commenting :width(w),length(l) does not give error while declaring width= w, length = l is giving error.

CAN ANYONE PLZZZ EXPLAIN THIS TO ME........
Oct 22 '06 #1
2 1411
arne
315 Expert 100+
#include<iostream.h>
class Room
{
int length;
int width;

public:
Room()
{}
Room(int l,int w=0) : width(w),length(l)
{
}
};

void main()
{
Room objRoom1;
Room obj2Room2(12,8);
}

This program is not giving any error.Now my question is : wat is the signifcance of this type of constructor declaration Room(int l,int w): width(w),legth(l)

y data member is defined as a function declaration and w and l as argument?
Note that commenting :width(w),length(l) does not give error while declaring width= w, length = l is giving error.

CAN ANYONE PLZZZ EXPLAIN THIS TO ME........
The part in bold letters in your post is called a "constructor initializer list". It is a sequence of statements that tell the compiler to initialize the corresponding members with the values in brackets. It is 'better' (more efficient) than

Expand|Select|Wrap|Line Numbers
  1. Room(int l,int w=0) {
  2.         length = l;
  3.         width = w;
  4. }
  5.  
since the members are always initialized and only changed in the constructor's body. The net effect, of course, is the same.
Oct 22 '06 #2
Shana
20
cooll...... I hav never come across this kinda of constructor declaration.
Thanks...!!
Oct 22 '06 #3

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

Similar topics

6
by: Pierre-Yves | last post by:
Hello, I would like to prevent my perl program to be executed several times simultaneously (if the program is already running, I would like to display a message like "another instance of this...
2
by: Jak Sparrow | last post by:
What are some good ways to programmatically check for software already installed on a computer? For example, to check a version of Internet Explorer, a program can check the registry for the...
5
by: zimmy | last post by:
Hi, Is it possible to check whether ASP.NET is installed on a machine, within a program that I'm writing in C#? And if it's installed, can I check if it is enabled? How? Thanks
3
by: Brian Henry | last post by:
I want to make a schedule of events to occur in a windows service (kinda like a scheduler) so the user can specify through an external interface to do a task at a certain time... like this 8pm -...
4
by: John Smith | last post by:
Hi I'm porting some C++ code to new platforms and have some 1-byte aligned structures which need a specific size. Since datatypes can vary on different platforms (which I found out the hard way...
12
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
5
by: RvGrah | last post by:
I've built a small app to deploy my apps in a small domain, just for my own use when I make small updates to pass to my end users. My app uses File.Copy, and works fine except that it takes a long...
0
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
Hi, We want to write a program (Prog_A) to check the activities of another program (Prog_B). If there is no activity on the Prog_B for a period of time, the Prog_A need send a message to close...
9
by: chutsu | last post by:
hi I got a simple program, and I was wondering how do you check if the string in an array = a string. For example if I put "APPLE" in array Array then how can I check it with a if statement. if...
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.