Domanda

I'm trying to make wrapper using variadic function. However, I got operand of sizeof may not be a function error from func_t func = va_arg(args, func_t); in Visual studio 2013. Nesting variadic function in C++ is not allowed? or is there any other solution for doing this job?

(I skipped redundant part of A::Outerfunc)

int A::Outerfunc(int nargs, ...) {

    if (nargs != 3) {
        cout << "Wrong argument number: " << std::endl;
        exit(1);
    }

    va_list args;

    va_start(args, nargs);
    typedef double func_t(int nargs, ...);

    double *f = va_arg(args, double *);
    func_t func = va_arg(args, func_t);
    double *fprime = va_arg(args, double *);

    va_end(args);

    return 0;
}
È stato utile?

Soluzione

You just need to make func_t a pointer-to-function, rather than a function....

typedef double (*func_t)(int nargs, ...);

See http://ideone.com/cF48S7

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top