我在我的代碼中有這個。如何計算兩個size_t變量的最大值
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
是一個unsigned int。那麼爲什麼這是一個問題,我如何解決這個問題。
與編譯:
$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',但我不知道候選人來了從? – UncleBens 2010-11-19 21:02:45
我無法在gcc 4.4.1上重現這一點。你能發佈一個完整的測試程序嗎? – ssegvic 2010-11-19 21:03:43
添加std :: to max解決了這個問題我認爲max被另一個頭文件或其他東西掩蓋了。 – 2010-11-19 21:07:11