Visual Studio不允许使用默认参数吗? [英] Visual studio not allowing ommision of default parameters?

查看:207
本文介绍了Visual Studio不允许使用默认参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用opencv的C ++项目上使用VS2010. opencv中的许多调用对于函数的最后几个参数都具有默认参数.但是,在函数调用中省略这些参数时,Visual Studio会抱怨并说"functionname: too few arguments for call

I am using VS2010 on a C++ project using opencv. Many of the calls in opencv have default parameters for the last few parameters to functions. However, when omitting these parameters in function calls, Visual Studio complains and says "functionname: too few arguments for call

这是Visual Studio的怪癖吗?我可以关闭某个地方的设置吗?为什么会这样.该代码在g ++下可以正常编译.

Is this a quirk of visual studio? Is it a setting somewhere that I can turn off? Why is this occurring. The code compiles fine under g++.

修改

例如,

#include <cv.h>
#include <cxcore.h>

int main()
{

    CvMat *rotation_vector = cvCreateMat(3,3, CV_64FC1);
    double rotation[] = { 0, 1, 0,
                -1, 0, 0,
                0, 0, 1 };

    cvInitMatHeader(rotation_vector, 3, 3, CV_64FC1, rotation, 2147483647); // works
        cvInitMatHeader(rotation_vector, 3, 3, CV_64FC1, rotation); // doesn't work
    return 0;
}

推荐答案

cvInitMatHeader()的声明是这样的:

CVAPI(CvMat*) cvInitMatHeader( CvMat* mat, int rows, int cols, int type,
    void* data CV_DEFAULT(NULL), int step CV_DEFAULT(CV_AUTOSTEP) ); 

CV_DEFAULT的定义看起来像这样:

The definition of CV_DEFAULT looks something like this:

#ifdef __cplusplus
    #define CV_DEFAULT(val) = val
#else
    #define CV_DEFAULT(val)
#endif

因此,看来您的Visual C ++编译器实际上是在C模式而不是C ++模式下进行编译.在C模式下,不会定义__cplusplus,因此CV_DEFAULT不会扩展为任何内容.因此,函数声明似乎没有默认参数.

So it appears that your Visual C++ compiler is actually compiling in C mode and not C++ mode. In C mode, __cplusplus would not be defined, so CV_DEFAULT expands to nothing. Therefore, it appears that the function declaration does not have default parameters.

检查您的项目设置,并确保您正在编译C ++模式下的代码.也就是说,确保启用了/Tp/TP编译器开关.您还应该确保您的C ++文件具有.cpp文件扩展名.

Check your project settings and make sure you're compiling the code in C++ mode. That is, ensure that the /Tp or /TP compiler switch is enabled. You should also make sure your C++ files have the .cpp file extension.

这篇关于Visual Studio不允许使用默认参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆