Call function with default argument from .dll with c++

前端 未结 2 1429
春和景丽
春和景丽 2021-01-21 23:37

I have a function defined in the Header of my .dll

void calculo(vector A, vector B, double &Ans1, double jj);

in t

相关标签:
2条回答
  • 2021-01-22 00:27

    Try add standard parameter value to function pointer type declaration:

    typedef void(_stdcall *f_funci)(vector A, vector B, double &Ans1, double jj = 36.5);

    Default argument value is part of function signature, compiler does not put it into function code.

    0 讨论(0)
  • 2021-01-22 00:32

    Default arguments:

    Are only allowed in the parameter lists of function declarations

    If you don't want to default the argument in the header you could accomplish what you're trying to do by overloading the function:

    void calculo(const vector<double>& A, const vector<int>& B, double &Ans1, const double jj);
    void calculo(const vector<double>& A, const vector<int>& B, double &Ans1) { calculo(A, B, Ans1, 36.5); }
    

    As a bonus comment, please pass vectors by constant reference as passing by value incurs the potentially expensive copy cost.

    0 讨论(0)
提交回复
热议问题