我正在使用Visual Studio 2012(但使用VC++ 2010构建工具),并且我有这两个重载的函数(下面的签名)在一个类中定义,我稍后在另一个函数中调用类实例化一流(下文):Visual C++ 2010接受字符串bool重载函数
Defined in the class:
Node CreateNode(Node *parent,string name,string node_text,bool expects_node = true);
Node CreateNode(Node *parent,string name, string attribute, string value,bool expects_node = true)
Calling these functions in the macro:
Node axis1 = handler->CreateNode(&sparse,"axis","id","trigger_pt");
当我做函数调用,它调用第一个函数,而不是第二个!所以它将第二个字符串视为布尔值!但是,当我为函数调用添加“true”时,它会按预期调用第二个函数。任何人都可以解释吗?谢谢!
或者添加第三个接受'const char *'的重载,使其自动完成。 – GManNickG 2013-03-25 19:12:57
我有时希望显式参数...'void f(explicit const bool b);'。也许用C++ 2100?顺便说一句:找到完整的转换顺序[这里](http://stackoverflow.com/a/15032114/2073257)。 – 2013-03-25 19:13:51
@GManNickG谢谢,我补充说。 – 2013-03-25 19:14:09