c++编译问题
程序大概是这样:
template<typename T>
class Avl {
std::list<T*> pdata;
int add(const T *item) {
pdata.push_back(item);
}
};
main() {
node_t a;
Avl<node_t> avl;
avl.add(&a)
}
然后编译报错如下:
In file included from ../Welcome_1/welcome.cc:33:0:
../Welcome_1/Avl.h: In instantiation of ‘int Avl<T>::add(const T*) [with T = node_t]’:
../Welcome_1/welcome.cc:129:15: required from here
../Welcome_1/Avl.h:112:5: error: no matching function for call to ‘push_back(const node_t*&)’
pdata.push_back(item);
^
In file included from /usr/include/c++/5.3.1/list:63:0,
from ../Welcome_1/Avl.h:11,
from ../Welcome_1/welcome.cc:33:
/usr/include/c++/5.3.1/bits/stl_list.h:1088:7: note: candidate: void std::list<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = node_t*; _Alloc = std::allocator<node_t*>; std::list<_Tp, _Alloc>::value_type = node_t*] <near match>
push_back(const value_type& __x)
^
/usr/include/c++/5.3.1/bits/stl_list.h:1088:7: note: conversion of argument 1 would be ill-formed:
In file included from ../Welcome_1/welcome.cc:33:0:
../Welcome_1/Avl.h:112:5: error: invalid conversion from ‘const node_t*’ to ‘std::list<node_t*>::value_type {aka node_t*}’ [-fpermissive]
pdata.push_back(item);
不明白为什么函数参数不匹配,明明 push_back(const value_type& __x) 就应该是 push_back(const node_t*&),请大家帮忙看下。