On November 10, 2009 10:24:54 am Manohar Vanga wrote:
> I have a problem that I am trying to solve involving variable argument
> lists in C++. I have two classes as shown below (parent and child
> classes):
>
> class A
> {
> A(int numargs, ...);
> };
> class B : public A
> {
> B(int numargs, ...);
> };
>
> How can I pass the variable argument list in B simply to the parent A's
> constructor? Currently the solution I am employing is as follows:
>
> class A
> {
> A() {}
> init(int numargs, va_list args) {.........}
> };
>
> class B
> {
> B(int numargs, ...)
> {
> va_list argptr;
> va_start(argptr, numargs);
> init(numargs, argptr);
> va_end(argptr);
> }
> };
>
> I am manually calling a function to do the work after converting the
> variable list into a va_lst. Is there any way to directly pass the variable
> list in class B into class A's constructor? Please help!
>
> Regards
> Manohar
>
Manohar,
It is not a good idea to use the var args stuff from C in C++, in fact GNU C++
has deprecated the support for it
You may want to consider alternatives such as overloaded constructors(if you
know maximum no of parameters), passing in a vector or the way already have it
- init(numargs, ...)
See http://www2.research.att.com/~bs/C++0xFAQ.html#variadic-templates to know
what Bjarne Stroustrup suggests
If you still want to do the same C non-portable way, try this:
http://www.velocityreviews.com/forums/t594152-passing-variable-parameters-to-
base-constructor.html
Regards,
Satish
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]