我有以下界面
virtual void send_command( const std::string& command, const std::string& key, const std::string& value, bool pipeline = true );
virtual void send_command( const std::string& command, const std::string& key, bool pipeline = true );
virtual void send_command( const std::string& command, bool pipeline = true );
这在一个类中完全实现,然后我将调用如下:
c.send_command("MUTLI");
c.send_command("SET", "foo", "bar");
c.send_command("GET", "foo");
c.send_command("EXEC");
当我检查调用了哪个方法实现时,我看到第三次调用(GET foo)最终到达了最后一个实现:
virtual void send_command( const std::string& command, bool pipeline = true );
其中“foo”被隐式转换为布尔值。当我使用显式 c-cast 对这样的字符串进行调用时,命中第二个实现(字符串、字符串、布尔值)的“SET”、“foo”、“bar”也同样重要
c.send_command("GET", (std::string)"foo");
预期的方法被调用。
我正在使用带有 C++11 的 gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)。