Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Something important C++ is missing
Index -> Programming, C++ -> C++ Tutorials
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
r691175002




PostPosted: Mon May 05, 2008 10:21 pm   Post subject: Re: RE:Something important C++ is missing

avok23 @ Mon May 05, 2008 8:48 pm wrote:
i just wonder why any one would do that. What kind of function would require that?

There has been two pages of discussion in this thread on that topic.

I personally don't see this as too much of a failing of C++. The situations that have been presented where this would be useful seem contrived and work fine with a sentinel value.

More importantly, if the programmer supplies default argument, I don't see why it is necessary to go around their back and have the function act differently than if they just let the function provide the same value.

If I see a function with the signature void foo (int bar = 0); I expect it to work the same whenever it is provided with a 0, no matter where the 0 comes from.
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Tue May 06, 2008 10:01 am   Post subject: Re: RE:Something important C++ is missing

r691175002 @ 2008-05-05, 10:21 pm wrote:
avok23 @ Mon May 05, 2008 8:48 pm wrote:
i just wonder why any one would do that. What kind of function would require that?

There has been two pages of discussion in this thread on that topic.

I personally don't see this as too much of a failing of C++. The situations that have been presented where this would be useful seem contrived and work fine with a sentinel value.

More importantly, if the programmer supplies default argument, I don't see why it is necessary to go around their back and have the function act differently than if they just let the function provide the same value.

If I see a function with the signature void foo (int bar = 0); I expect it to work the same whenever it is provided with a 0, no matter where the 0 comes from.


To go back to my socket example, there are two options: sending on a specific port and sending on the default port. The default port is socket specific - you decide it when you open the socket - and cannot be used as a default parameter to any function. So, one of the normal ports must now be used to indicate using the default port - or a function must be overloaded (and with generic virtual base classes and templates... that's a pain).
matt271




PostPosted: Fri May 06, 2011 6:37 pm   Post subject: Re: Something important C++ is missing

i think if you intend to have a different function for when no argument(or a lack of one or more) is/are provided, and a function for when an argument(or 'all' of them) is/are provided; then this is the time u should use overloading...

is that not what its for?
Insectoid




PostPosted: Fri May 06, 2011 6:48 pm   Post subject: RE:Something important C++ is missing

Check the timestamps matt. You're a few years late.

I think it would be interesting if you could call a function that takes, say, a pointer, an integer and a float in the following manner:

code:
int foo (int*, int, float){
    //stuff
}

cout << foo (int*, some_int, float);


This would specify exactly which function you're calling, allowing for passing in only some parameters without ambiguous overloading.

This would not allow you to change the behavior of the function based on which variables were passed, however if you really want to do that you might as well just overload it.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 34 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: