作者liquidelf ( 123)
看板C_and_CPP
標題[問題] 請問使用template的error
時間Thu Feb 11 13:15:44 2010
新手第一次使用function template
程式碼如下
template <class T> T** G(int nRows, int nCols)
{
T **ppi;
T *pool;
T *curPtr;
ppi = new T*[nRows];
pool = new T [nRows * nCols];
curPtr = pool;
for( int i = 0; i < nRows; i++)
{
*(ppi + i) = curPtr;
curPtr += nCols;
}
return ppi;
}
main呼叫時
int main(int argc, char *argv[])
{
double **d = G(5,3);
system("PAUSE");
return EXIT_SUCCESS;
}
即出現錯誤
no matching function for call to `G(int, int)'
第一次使用 function template,請問這該怎麼解決呢
希望大家不吝指導
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.103.207
1F:推 littleshan:function template 只拿回傳 type 當參數時, 02/11 13:49
2F:→ littleshan:要明確指定它的 type 02/11 13:50
3F:→ littleshan:你的例子中改用 G<double>(5, 3) 即可 02/11 13:50
4F:→ liquidelf:謝謝你 ^____^ 02/11 14:00