我正在编写自己的库以获得乐趣,但我遇到了一个问题。这是我的代码。
#include "utility/memory.h"
using namespace libnate::utility;
template <class T>
void copy( T *src, T *dest, size_t size ) {
for( size_t i = 0; i < size; ++i ) {
dest[i] = src[i];
}
}
template void copy( int *, int *, size_t );
template <class T>
size_t resize_array( T *&array, size_t internal_size ) {
size_t nu_size = internal_size * 2 + 1;
T *tmp_array = new T[nu_size];
copy<T> ( array, tmp_array, internal_size );
delete [] array;
array = tmp_array;
return nu_size;
}
template size_t resize_array( int *&, size_t );
G++ 在我的复制调用中抱怨某种模棱两可的调用。
这是输出。
njackson@glados:~/libnate$ make
cd src && make
make[1]: Entering directory `/home/njackson/libnate/src'
g++ -c -I../include memory.cpp
memory.cpp: In function ‘size_t resize_array(T*&, size_t) [with T = int, size_t = unsigned int]’:
memory.cpp:25:46: instantiated from here
memory.cpp:18:2: error: call of overloaded ‘copy(int*&, int*&, size_t&)’ is ambiguous
memory.cpp:18:2: note: candidates are:
memory.cpp:5:6: note: void copy(T*, T*, size_t) [with T = int, size_t = unsigned int]
../include/utility/memory.h:11:6: note: void libnate::utility::copy(T*, T*, size_t) [with T = int, size_t = unsigned int]
make[1]: *** [memory.o] Error 1
make[1]: Leaving directory `/home/njackson/libnate/src'
make: *** [_] Error 2
任何帮助表示赞赏。谢谢。