【发布时间】:2023-04-02 00:18:02
【问题描述】:
我的代码中有这个。
vector<unsigned int> import;
vector<unsigned int> aquired;
. . .
size_t new_size = max(import.size(),aquired.size());
我得到这个错误:
error: more than one instance of
overloaded function "max" matches the
argument list:
function "max(int, int)"
function "max(unsigned int, unsigned int)"
function "max(int, unsigned int)"
function "max(unsigned int, int)"
function "max(long long, long long)"
function "max(unsigned long long, unsigned long long)"
function "max(long long, unsigned long long)"
function "max(unsigned long long, long long)"
function "max(float, float)"
function "max(double, double)"
function "max(float, double)"
function "max(double, float)"
argument types are: (size_t, size_t)
我的理解是size_t 是一个无符号整数。那么为什么会出现这个问题以及如何解决它。
编译:
$gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
$nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Wed_Sep__8_17:12:45_PDT_2010
Cuda compilation tools, release 3.2, V0.2.1221
【问题讨论】:
-
size_t不一定是unsigned,但我想知道候选人来自哪里? -
我无法在 gcc 4.4.1 上重现它。你能发布一个完整的测试程序吗?
-
将 std:: 添加到 max 解决了我认为 max 被另一个标题或其他东西掩盖的问题。
-
@UncleBens 引用好吗?我真的怀疑这是真的,除了非常古老的不符合标准的实现。
sizeof的返回类型小于零没有任何意义,C99 明确将size_t定义为无符号整数类型。