473,395 Members | 1,677 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.

defaulting argument to previous argument

It is illegal in g++ to default argument #6 to argument #5. I get an
error

[bhushit@x1-6-00-c0-49-b3-8a-c5 constantsum]$ g++ -g ../../surface.cpp
.../../../segments/segment.cpp
.../../../segments/geodesic-geodesic-state.cpp
.../../../segments/circular-circular-state.cpp *.cpp
ysumsphere.cpp:33: `where_00_ends' was not declared in this scope

for the code
Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends, int where_0max_ends = where_00_ends ) {
....
}

Definition : Monkeying
"Being able to express default arguments in terms of explicit
arguments"

My questions:
1. By the time the compiler sees arg #6, arg #5 is already seen. Why
does it fuss?
2. I can see cases in which Monkeying prevents unwanted assumptions
about explicit arguments. Do I miss a lesson in designing?
3. I fail to see anything fundamentally wrong with Monkeying. It is
just a matter of adding some more code to prologue of a function code.
Does it conflict with some absence of specification of order of
evaluation of arguments in C++?
4.I am sure I am neither the first nor the last to need this. How to
solve the situation the best? I do not want to put this burden on the
user of the class.

Any help appreciated.
-Bhushit
Jul 22 '05 #1
5 1052

"Bhushit Joshipura" <bh*****@hotmail.com> wrote in message news:84**************************@posting.google.c om...
My questions:
1. By the time the compiler sees arg #6, arg #5 is already seen. Why
does it fuss?


There is nothing that requires left to right evaluation of function arguments.
Jul 22 '05 #2
"Ron Natalie" <ro*@sensor.com> wrote in message news:<3f***********************@news.newshosting.c om>...
"Bhushit Joshipura" <bh*****@hotmail.com> wrote in message news:84**************************@posting.google.c om...
My questions:
1. By the time the compiler sees arg #6, arg #5 is already seen. Why
does it fuss?


There is nothing that requires left to right evaluation of function arguments.


Still questions #2 and #4 remain.
1. What if I need such a function? Am I the only one feeling the need?
2. How can I avoid putting unnecessary restriction on the ranage of
the arguments to be defaulted?
3. Is there a design strategy that would let me avoid this trap?
4. Why should my client be bothered with "always passing last
argument"?

-Bhushit
Jul 22 '05 #3
Bhushit Joshipura wrote:


Still questions #2 and #4 remain.
1. What if I need such a function? Am I the only one feeling the need?
2. How can I avoid putting unnecessary restriction on the ranage of
the arguments to be defaulted?
3. Is there a design strategy that would let me avoid this trap?
4. Why should my client be bothered with "always passing last
argument"?

You can use overloading to get full control over this process. How about
something like:

class Ysumsphere {
public:
Ysumsphere::Ysumsphere( int x_min,
int x_max,
int y_min,
int y_max,
int where_00_ends,
int where_0max_ends ) :
mXMin( x_min ),
mXMax( x_max ),
mYMin( y_min ),
mYMax( y_max ),
mWhere00Ends( where_00_ends ),
mWhere0MaxEnds( where_0max_ends ) { /* do something */ }

Ysumsphere::Ysumsphere( int x_min,
int x_max,
int y_min,
int y_max,
int where_00_ends ) :
mXMin( x_min ),
mXMax( x_max ),
mYMin( y_min ),
mYMax( y_max ),
mWhere00Ends( where_00_ends ),
mWhere0MaxEnds( where_00_ends ) { /* do something */ }
private:
int mXMin ;
int mXMax ;
int mYMin ;
int mYMax ;
int mWhere00Ends ;
int mWhere0MaxEnds ;
} ;

void yuck()
{
Ysumsphere foo( 1, 2, 3, 4, 5, 6 ) ;
Ysumsphere bar( 1, 2, 3, 4, 5 ) ;
return ;
}

--
CrayzeeWulf
Jul 22 '05 #4

"Bhushit Joshipura" <bh*****@hotmail.com> wrote in message
news:84**************************@posting.google.c om...
It is illegal in g++ to default argument #6 to argument #5. I get an
error

[bhushit@x1-6-00-c0-49-b3-8a-c5 constantsum]$ g++ -g ../../surface.cpp
../../../segments/segment.cpp
../../../segments/geodesic-geodesic-state.cpp
../../../segments/circular-circular-state.cpp *.cpp
ysumsphere.cpp:33: `where_00_ends' was not declared in this scope

for the code
Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends, int where_0max_ends = where_00_ends ) {
...
}

Definition : Monkeying
"Being able to express default arguments in terms of explicit
arguments"

My questions:
1. By the time the compiler sees arg #6, arg #5 is already seen. Why
does it fuss?
because the order of evaluation of arguments is implementation defined.
Further teh standard specifically prohibits this (for the above reason)
2. I can see cases in which Monkeying prevents unwanted assumptions
about explicit arguments. Do I miss a lesson in designing?
3. I fail to see anything fundamentally wrong with Monkeying. It is
just a matter of adding some more code to prologue of a function code.
Does it conflict with some absence of specification of order of
evaluation of arguments in C++?
Yes - where_00_ends is a local variable that may or may not have been
initialised to the value of the supplied parameter when it is used to init
where_0max_ends
4.I am sure I am neither the first nor the last to need this. How to
solve the situation the best? I do not want to put this burden on the
user of the class.
Simple - use overloading:

Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends, int where_0max_ends) ;

Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends) ;

Unfortunately the second ctor can't call the first but the that doesn't
really matter for simple classes.

If you have more complicated construction and really want the effect of ctor
calling ctor then the same effect can be acheived by pushing the core stuff
into a base class - the overloaded ctors then call call the base ctor with
all the 'default' args.

Any help appreciated.
-Bhushit

Jul 22 '05 #5
ske
Nick Hounsome wrote:
"Bhushit Joshipura" <bh*****@hotmail.com> wrote in message
news:84**************************@posting.google.c om...
It is illegal in g++ to default argument #6 to argument #5. I get an
error

[bhushit@x1-6-00-c0-49-b3-8a-c5 constantsum]$ g++ -g ../../surface.cpp
../../../segments/segment.cpp
../../../segments/geodesic-geodesic-state.cpp
../../../segments/circular-circular-state.cpp *.cpp
ysumsphere.cpp:33: `where_00_ends' was not declared in this scope

for the code
Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends, int where_0max_ends = where_00_ends ) {
...
}

Definition : Monkeying
"Being able to express default arguments in terms of explicit
arguments"

My questions:
1. By the time the compiler sees arg #6, arg #5 is already seen. Why
does it fuss?

because the order of evaluation of arguments is implementation defined.
Further teh standard specifically prohibits this (for the above reason)

2. I can see cases in which Monkeying prevents unwanted assumptions
about explicit arguments. Do I miss a lesson in designing?
3. I fail to see anything fundamentally wrong with Monkeying. It is
just a matter of adding some more code to prologue of a function code.
Does it conflict with some absence of specification of order of
evaluation of arguments in C++?

Yes - where_00_ends is a local variable that may or may not have been
initialised to the value of the supplied parameter when it is used to init
where_0max_ends

4.I am sure I am neither the first nor the last to need this. How to
solve the situation the best? I do not want to put this burden on the
user of the class.

Simple - use overloading:

Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends, int where_0max_ends) ;

Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends) ;

Unfortunately the second ctor can't call the first but the that doesn't
really matter for simple classes.

If you have more complicated construction and really want the effect of ctor
calling ctor then the same effect can be acheived by pushing the core stuff
into a base class - the overloaded ctors then call call the base ctor with
all the 'default' args.


Alternatively if the parameters are only used to initialise member
variables then a single constructor with a member initialisation list
should do the trick (without having to duplicate constructors or add a
base class):

ie:
Ysumsphere::Ysumsphere ( int x_min, int x_max, int y_min, int y_max,
int where_00_ends) : where_0max_ends(where_00_ends) { ... }

Assuming of course that where_0max_ends is a member of the class.
Jul 22 '05 #6

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

Similar topics

4
by: Jyrki Keisala | last post by:
Hi, I have an XML file which I want to present as a HTML table, and I'm looking for a quick way of defaulting all empty elements in my XML file to a nbsp (using the   notation) in my XSL...
5
by: Manuel Maria Diaz Gomez | last post by:
Thanks Victor for your previous answer! I have the following problem: I would like to implement an interface class that defines a pure virtual method that could take any parameter as input, ...
2
by: xuatla | last post by:
The following is just a sample code to demostrate my question: ----------- template <typename T> class C { public: friend void f1(double i=2) { std::cout << i; } ; };
10
by: int2str | last post by:
All, As the simple sample program below demonstrates, function arguments are destroyed after the return value of the function has been evaluated. As opposed to local function variables, which...
7
by: Roman Susi | last post by:
Hi! it is interesting that I found this syntax error: File "<stdin>", line 1 str('sdfd', **a,) ^ SyntaxError: invalid syntax
8
by: DaFrizzler | last post by:
Hi, I have received the following email from a colleague, and am quite frankly baffled by the idea. I am just wondering if anyone has any advice or suggestions about this???? === BEGIN MAIL...
2
by: Sarah Yarok | last post by:
Has anyone seen this strange behavior? My 97 database accidentally got converted to 2002. When I converted it back, all fonts on screen (and in print) seem to be defaulting to MS sans serif. I...
9
by: Mike | last post by:
While trying to write a recursive function involving lists, I came across some (to me) odd behavior which I don't quite understand. Here's a trivial function showing the problem. for itm in l:...
7
by: mirandacascade | last post by:
The questions are toward the bottom of this post. Situation is this: 1) Access 97 2) Multi-user appplication 3) SQL Server 2000 4) Sporadically (i.e. less than 1% of the time) encounter the...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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.