简体   繁体   中英

calling a function in C++ with default arguments

I have a function Func(string str,int*i=NULL,int*j=NULL,bool ok=false); I called it as 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. The 3rd and 4th parameters will take NULL and false respectively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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