gpt4 book ai didi

c++ - 运算符重载失败,运算符 [] 和运算符转换为 int

转载 作者:搜寻专家 更新时间:2023-10-31 01:02:48 25 4
gpt4 key购买 nike

<分区>

以下程序无法在 VS 2013 SP3 上编译。问题是什么?我该如何避免?

#include <string>

class Test
{
public:
operator int() const
{
return 42;
}
inline Test *operator[](const std::string &name)
{
return this;
}
};

int main(int argc, char* argv[])
{
Test ts;
Test *k = ts["huhu"];
return 0;
}

输出是:C2666:数字重载有相似的转换

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com