| re: va_start and template functions do not compile under gcc 2.7.2
"frankg" wrote:
: When I compile this file
: ------------------------------------------------------
: #include <stdarg.h>
:
:
: template <class Any>
: void var_arg_func(int dimension_count, ...)
: {
: int dimensions[4];
: va_list ap;
:
: va_start(ap, dimension_count); // <- error
:
:
: for (int i = 0; i < 3; i++)
: {
: dimensions[i] = va_arg(ap,int); // <- error
: }
: }
: ------------------------------------------------------
: I get the following obscure error message:
: test.cpp:10: sorry, not implemented: initializer contains unrecognized
: tree code
: test.cpp:15: sorry, not implemented: initializer contains unrecognized
: tree code
:
: If I make the function to be non-templated, it compiles.
:
: Either version compiles under MSVC++ 6.0.
:
: I am using the gcc 2.7.2 that ships with Tornado 2.0 from
: WindRiver.
:
: Can anyone explain this error message?
: I need to get this code to compile.
:
: I have a templated class that I wrote that implements a
: multi-dimensional container. Since it is a container it must be
: templated.
: Being multi-dimensional the functions that require an index use
: the elipsis ... operator.
The code you posted assumes a set size of 3 integer arguments, so getting
that code to compile would be as simple as taking out the ellipses and
putting in an array argument and reading that. However, I don't think the
code you posted is what you want to actually compile (since your function is
parameterized but never uses the template parameter and the ellipses suggest
many possible numbers of arguments).
If the ellipses mean you just want to get passed a collection of values you
know are integers, just set a second argument of std::vector<int>, if they
are parametrized by the template, set a second argument of std::vector<Any>,
and if the arguments really must vary in type, you need to include a
descriptor argument which specifies what the format of those arguments are
and then you can try a std::vector<boost::any> or some other generic type
container. I am not sure why your code will not compile, but there seem to
be several alternate designs that might be more typesafe as well as being
more likely to compile.
--
/////////////////////////////////////////////
galathaea: prankster, fablist, magician, liar |