简体   繁体   English

使用默认参数调用 C++ 中的函数

[英]calling a function in C++ with default arguments

I have a function Func(string str,int*i=NULL,int*j=NULL,bool ok=false);我有一个函数Func(string str,int*i=NULL,int*j=NULL,bool ok=false); I called it as Func(some_string,false);我称它为Func(some_string,false);

And program is crashing..Because the order I'm calling with --is wrong??程序崩溃了..因为我用 -- 调用的顺序是错误的??

如果您希望为ok指定一个值,您还必须为它之前的所有参数指定值。

Yes.是的。 The second parameter is expecting a int value and you are passing a bool value.第二个参数需要一个 int 值,而您正在传递一个 bool 值。 The 3rd and 4th parameters will take NULL and false respectively.第三个和第四个参数将分别为 NULL 和 false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM