【发布时间】:2020-11-25 04:56:48
【问题描述】:
出现Call to constructor of 'Binary' is ambiguous 的错误消息,该错误消息仅在macOS 上使用LLVM 编译器时出现,但在Windows 上不会出现。
此外,类的构造函数参数看起来也不一样。
class Binary {
public:
Binary() = default;
Binary(uintmax_t containerSize);
Binary(unsigned char binary);
Binary(std::initializer_list<unsigned char> binaryList);
// .....
};
// When using
// fileSize is `std::streamoff` data type
Binary fileContent((unsigned long long)fileSize) // << This line is causing the problem.
我的班级出了什么问题?
【问题讨论】:
-
如果意图是调用第二个 ctor,为什么要转换为
unsigned long long而不是uintmax_t?我敢打赌,它们在您的 Windows 版本上是相同的类型根,但在您的 MacOS 版本上是不同的。 -
uintmax_t是unsigned long long,所以我认为unsigned long long是合适的,而且我在 macOS 和 windows 上做了同样的事情,但 windows 没有出现该消息。 -
是的,我们明白了;你在你的帖子里说了这么多。现在再读一遍我说的话,具体来说,不同平台上的
uintmax_t不一定必然与unsigned long long同义,所以你的第一句话uintmax_t是unsigned long long是不是普遍准确的。
标签: c++ class compiler-errors