Does anyone have a good way to handle the following situation...
public void FilterResults(int a, int b)
I need to filter based on none, one, or both parameters, so they both
need to be "optional". Overloading is eliminated as a possible
solution because both parameters are the same type. Params is
possible, but it doesn't seem like I can keep track of which params are
passed in (which is which)...Any ideas?
Thanks, Brian 4 1140
You could created a struct for each of the parameters that only contains
the single named int value. Then create overloads of the routines that
accept the structs by name. It causes a bit of overhead to setup for
the call and to deal with it but it would give you a lightweight way to
get the functionality you need.
Have A Better One!
John M Deal, MCP
Necessity Software
Brian wrote: Does anyone have a good way to handle the following situation...
public void FilterResults(int a, int b)
I need to filter based on none, one, or both parameters, so they both need to be "optional". Overloading is eliminated as a possible solution because both parameters are the same type. Params is possible, but it doesn't seem like I can keep track of which params are passed in (which is which)...Any ideas?
Thanks, Brian
I usually abandon overloading at this point and simply change the name:
public void FilterResults()
public void FilterResultsOnA(int a)
public void FilterResultsOnB(int b)
public void FilterResults(int a, int b)
At least this way the method name tells the reader what the call is
doing.
I usually abandon overloading at this point and simply change the name:
public void FilterResults()
public void FilterResultsOnA(int a)
public void FilterResultsOnB(int b)
public void FilterResults(int a, int b)
At least this way the method name tells the reader what the call is
doing.
Hi,
I totally agree with you and I think that this is the best way of doing it.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com... I usually abandon overloading at this point and simply change the name:
public void FilterResults()
public void FilterResultsOnA(int a)
public void FilterResultsOnB(int b)
public void FilterResults(int a, int b)
At least this way the method name tells the reader what the call is doing. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Terje Slettebø |
last post by:
To round off my trilogy of "why"'s about PHP... :) If this subject have been
discussed before, I'd appreciate a pointer to it. I again haven't found it
in a search of the PHP groups.
The PHP...
|
by: Susan Baker |
last post by:
Hello everybody,
I'm new to C++ (I have some C background). I've read up on this topic a
few times but it just dosen't seem to be sinking in.
1. Whats the difference between overloading and...
|
by: Michał Januszczyk |
last post by:
is it possible to define schema for the following element ? :
<processor><param>arial</param><param>3.5</param><param>50</param><param>95</param><param>some text</param></processor
I want to...
|
by: uday |
last post by:
Does C supports overloading. I am thinking no. But some people are
saying yes. If yes how. Please answer with examples.
Also in c++ size of empty class is one. why. and what are the
default...
|
by: |
last post by:
Hi,
Why can I not overload on just the return type?
Say for example.
public int blah(int x)
{
}
|
by: Kejpa |
last post by:
Hi,
I have a function Sum as....
Function Sum(ByVal ParamArray Values() As Double) As Double
Dim rSum, itm As Double
For Each itm In Values
rSum += itm
Next
Return rSum
End Function
|
by: Fernando Berretta |
last post by:
Hello,
Is there some way to truly Overload a WebMethod (Without using MessageName)
??
Thanks in advance,
Fernando
|
by: placid |
last post by:
Hi all,
Is it possible to be able to do the following in Python?
class Test:
def __init__(self):
pass
def puts(self, str):
print str
|
by: PengYu.UT |
last post by:
Hi,
It seems that C++ does not allow overloading operators for primative
types, e.g. int, double. I'm wondering whether it is ture or there is
some walk-around?
Thanks,
Peng
#include...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
| |