//文件 a.h template class Array : public std::vector { public: T operator[](int index); Array& operator+=(T obj); Array& add(T obj); Array& del(int index); Array& join(T obj,int index); };

//文件 a.cpp template T Array::operator[](int index) { return this->at(index); }

template Array& Array::operator+=(T obj) { this->add(obj); return *this; }

template Array& Array::add(T obj) { this->push_back(obj); return *this; }

template Array& Array::del(int index) { this->erase(this->begin() + index); return *this; }

template Array& Array::join(T obj,int index) { this->insert(this->begin() + index, obj); return *this; }

C++23 模板类数组操作优化:解决常见报错

原文地址: https://www.cveoy.top/t/topic/qcNL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录