473,503 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typos in set functions

Is there any trick to avoid typos in set functions, such as

void date::set(int day, int month, int year) {
d_day = day;
month = month; // oops: should be d_month = month
d_year = year;
}
Jul 22 '05 #1
5 1098
Le mardi 30 novembre 2004 à 11:34, Siemel Naran a écrit dans
comp.lang.c++*:
Is there any trick to avoid typos in set functions, such as

void date::set(int day, int month, int year) {
d_day = day;
month = month; // oops: should be d_month = month
d_year = year;
}


const parameters can help in this case.

void date::set(const int day,const int month,const int year)
{
d_day = day;
month = month; // oops: compilation error
d_year = year;
}

--
___________ 2004-11-30 12:08:04
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
Jul 22 '05 #2
Siemel Naran wrote:
Is there any trick to avoid typos in set functions, such as
month = month; // oops: should be d_month = month


what about declaring the arguments "const" ?
Jul 22 '05 #3
Siemel Naran wrote:

Is there any trick to avoid typos in set functions, such as

void date::set(int day, int month, int year) {
d_day = day;
month = month; // oops: should be d_month = month
d_year = year;
}


Test your code.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #4
"Siemel Naran" <Si*********@REMOVE.att.net> wrote:
Is there any trick to avoid typos in set functions, such as

void date::set(int day, int month, int year) {
d_day = day;
month = month; // oops: should be d_month = month
d_year = year;
}


Turn up your compiler warning level? You may get
a warning that the statement has no effect.
Jul 22 '05 #5
"Old Wolf" <ol*****@inspire.net.nz> wrote in message
"Siemel Naran" <Si*********@REMOVE.att.net> wrote:

Is there any trick to avoid typos in set functions, such as

void date::set(int day, int month, int year) {
d_day = day;
month = month; // oops: should be d_month = month
d_year = year;
}


Turn up your compiler warning level? You may get
a warning that the statement has no effect.


OK, but many compilers only issues the warning only if month is a
fundamental or POD type. With a user defined operator=, the compiler can't
eally make the assumption that the statement has no effect (though would be
nice if it did).

Everyone, thanks for the pointers. Now how to avoid the problem

d_month = d_month; // oops: should be d_month = month

I suppose we could turn up the warning level and get a warning that variable
month is not used or test the code thoroughly. Is there a way to force a
compile error here?

Thanks.
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3326
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
15
3561
by: Manish Jethani | last post by:
Hi all, Is there a way to detect typos in a Python program, before actually having to run it. Let's say I have a function like this: def server_closed_connection(): session.abost() Here,...
25
2974
by: JKop | last post by:
Using MSWindows as an example: On MSWindows, there's a thing called the System Registry, which is a really big database that holds all the settings of the OS. There's API's for working with the...
2
3759
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
5877
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
3961
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
1
1360
by: southparkcab | last post by:
# include <stdio.h> # include <stdlib.h> # include <math.h> # define M_SQRT /* macro to insert blank lines on screen */ #define BLANK_LINE(n) {int i=0;for(i<(n);i++)fprintf(stderr,"\n";} ...
7
3946
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
0
7093
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
7348
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
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.