my class:
template <class type>
class List{
public:
List(){
_list = new type[10];
}
~List(){
delete this->_list;
}
private:
type* _list;
};
in main:
int main(){
List<std::string> l = List<std::string>();
return 0;
}
It happens only if I put non primitive variable in <>
and dont use new.
I can avoid this by doing it like this: List<string> *l = new List<string>();
What I'am missing? In my mind it should perfectly fine.
尝试删除[]而不是删除,因为您正在分配数组。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.