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

extensible math functions: variable number of arguments and class templates

I have a couple of questions about using a variable number of
arguments in a function call (...). The context is that I have some
mathematical functions I created. I currently pass them a pair of
numbers (doubles), and the functions only work in one dimension. I
would ideally like to extend them to work in N dimensions, which means
I want to pass some undefined number of pairs of arguments. I will
loop through the N arguments to do the math in N dimensions.

1. Some consider using a variable number of arguments unsafe, due to
type checking concerns. So, is there a another but simple way to
extend the function so I can pass it N pairs of numbers? Or would you
simply recommend heavy error checking in the functions?

2. Can the arguments in a variable number of arguments call to a
function be class templates? As in:

template <class T>
T do_math (class T, . . .)
{
. . .
}

Thanks in advance,

Alan

Jul 10 '07 #1
2 1881
On Jul 10, 6:46 am, "Alf P. Steinbach" <a...@start.nowrote:
Pass a vector of pairs.
or pass a pair of vectors:

#include <vector>

void do_math(const std::vector<double>& ,const std::vector<double>&);

void myfunc(){
std::vector<doublev1,v2;
v1[1]=someValue1;
v1[2]=someValue2;
//and so forth
...
do_math(v1,v2);
}
regards,
FM.
Jul 10 '07 #2
On Jul 10, 2:54 pm, "Alf P. Steinbach" <a...@start.nowrote:
* terminator:


On Jul 10, 6:46 am, "Alf P. Steinbach" <a...@start.nowrote:
Pass a vector of pairs.
or pass a pair of vectors:
#include <vector>
void do_math(const std::vector<double>& ,const std::vector<double>&);
void myfunc(){
std::vector<doublev1,v2;
v1[1]=someValue1;
v1[2]=someValue2;
//and so forth
...
do_math(v1,v2);
}

Perhaps you can figure out why I did not recommend that?
Please clarify your point ; I am not that sharp.

Jul 11 '07 #3

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

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
0
by: Anthony Baxter | last post by:
To go along with the 2.4a3 release, here's an updated version of the decorator PEP. It describes the state of decorators as they are in 2.4a3. PEP: 318 Title: Decorators for Functions and...
0
by: Jussi Mononen | last post by:
Hi, I'm having problems to successfully execute the test scripts on a Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up with the following error message "PARI: *** ...
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
9
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
3
by: carvalho.miguel | last post by:
hello, imagine you have a static class method that receives a function pointer, an int with the number of arguments and a variable number of arguments. in that static method you want to call...
10
by: William Krick | last post by:
I am writing an XSL transform that converts XML data about vehicles into XML data that will fill printed forms. The default form can handle up to 5 vehicles which I handle using subscripts... ...
9
by: Allen | last post by:
The arguments of function is variable. Given function address, argument type and data, how to dynamically call the function? The following is pseudo code. int count = 0; int offset = 0; char...
6
by: Bartholomew Simpson | last post by:
I'm trying to avoid (or at least, minimize) duplicity of effort. I have the following function: void Permissions::Exists(const unsigned int id, std::vector<Permission>::const_iterator& iter) {...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
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,...

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.