当我将枚举指定为第二个参数时,为什么 VisualC++ (2008) 会混淆“C2666:2 个重载具有相似的转换”,但在我定义布尔类型时却没有?
类型匹配不应该已经排除了第二个构造函数,因为它是“basic_string”类型吗?
#include <string>
using namespace std;
enum EMyEnum { mbOne, mbTwo };
class test {
public:
#if 1 // 0 = COMPILE_OK, 1 = COMPILE_FAIL
test(basic_string<char> myString, EMyEnum myBool2) { }
test(bool myBool, bool myBool2) { }
#else
test(basic_string<char> myString, bool myBool2) { }
test(bool myBool, bool myBool2) { }
#endif
};
void testme() {
test("test", mbOne);
}
我可以通过指定一个参考来解决这个问题 'ie. basic_string &myString' 但如果它是 'const basic_string &myString' 则不是。
还通过 "test((basic_string)"test", mbOne);" 显式调用 也有效。
我怀疑这与通过固有的“!= 0”将每个表达式/类型解析为布尔值有关。
好奇的评论都一样:)