Search Results

Search found 5 results on 1 pages for 'variableargumentlists'.

Page 1/1 | 1 

  • Using a function with variable argument strings

    - by wrongusername
    I was playing around a bit with functions with variable arguments, and decided to make a function to create vectors with the arguments. My function for creating an int vector worked... vector<int> makeIntVector(int numArgs, ...) { va_list listPointer; va_start(listPointer, numArgs); vector<int> made; for(int a = 0; a < numArgs; a++) made.push_back(va_arg(listPointer, int)); va_end(listPointer); return made; } but not my function for creating a string vector: vector<string> makeStringVector(int numArgs, string something, ...) { va_list listPointer; va_start(listPointer, something); vector<string> made; for(int a = 0; a < numArgs; a++) made.push_back(va_arg(listPointer, string)); va_end(listPointer); return made; } which crashes the program. What am I doing wrong?

    Read the article

  • Variable length argument list - How to understand we retrieved the last argument?

    - by hkBattousai
    I have a Polynomial class which holds coefficients of a given polynomial. One of its overloaded constructors is supposed to receive these coefficients via variable argument list. template <class T> Polynomial<T>::Polynomial(T FirstCoefficient, ...) { va_list ArgumentPointer; va_start(ArgumentPointer, FirstCoefficient); T NextCoefficient = FirstCoefficient; std::vector<T> Coefficients; while (true) { Coefficients.push_back(NextCoefficient); NextCoefficient = va_arg(ArgumentPointer, T); if (/* did we retrieve all the arguments */) // How do I implement this? { break; } } m_Coefficients = Coefficients; } I know that we usually pass an extra parameter which tells the recipient method the total number of parameters, or we pass a sentimental ending parameter. But in order to keep thing short and clean, I don't prefer passing an extra parameter. Is there any way of doing this without modifying the method signature in the example?

    Read the article

  • C++ Template Class Constructor with Variable Arguments

    - by david
    Is it possible to create a template function that takes a variable number of arguments, for example, in this Vector< T, C class constructor: template < typename T, uint C > Vector< T, C >::Vector( T, ... ) { assert( C > 0 ); va_list arg_list; va_start( arg_list, C ); for( uint i = 0; i < C; i++ ) { m_data[ i ] = va_arg( arg_list, T ); } va_end( arg_list ); } This almost works, but if someone calls Vector< double, 3 ( 1, 1, 1 ), only the first argument has the correct value. I suspect that the first parameter is correct because it is cast to a double during the function call, and that the others are interpreted as ints and then the bits are stuffed into a double. Calling Vector< double, 3 ( 1.0, 1.0, 1.0 ) gives the desired results. Is there a preferred way to do something like this?

    Read the article

  • Double variable argument list.

    - by Lukasz Lew
    I need something like this: class Node (left : Node*, right : Node*) I understand the ambiguity of this signature. Is there a way around it better than the following? class Node (left : Array[Node, right : Array[Node]) val n = new Node (Array(n1, n2), Array(n3)) Maybe some kind of separator like this? val n = new Node (n1, n2, Sep, n3)

    Read the article

  • how to pass variable arguments from one function to other in tcl

    - by vaichidrewar
    I want to pass variable arguments obtained in one function to other function but I am not able to do so. Function gets even number of variable arguments and then it has to be converted in array. Below is the example. Procedure abc1 gets two arguments (k k) and not form abc1 procedure these have to be passed to proc abc where list to array conversion it to be done. List to array conversion works in proc1 i.e. abc1 but not in second proc i.e. abc Error obtained is given below proc abc {args} { puts "$args" array set arg $args } proc abc1 {args} { puts "$args" array set arg $args set l2 [array get arg] abc $l2 } abc1 k k abc k k Output: k k {k k} list must have an even number of elements while executing "array set arg $l1" (procedure "abc" line 8) invoked from within "abc $l2" (procedure "abc1" line 5) invoked from within "abc1 k k" (file "vfunction.tcl" line 18)

    Read the article

1