[VC6]std::vector派生类无法调用std::vector的解决方法

简介: [VC6]std::vector派生类无法调用std::vector的解决方法
[VC6]std::vector派生类无法调用std::vector的解决方法
template<class _Ty, class _A = std::allocator<_Ty> >
class CTestVector : public std::vector<_Ty,_A >
{
 public:
  void clear()
  {
   std::vector<_Ty,_A >::clear();
  }
};

调用代码

CTestVector<int> vv;
 vv.clear();

出差提示:

'std::vector<int,class std::allocator<int> >::clear' : illegal call of non-static member function

解决方法

template<class _Ty, class _A = std::allocator<_Ty> >
class CTestVector : public std::vector<_Ty,_A >
{
 typedef std::vector<_Ty,_A > PARENT;

public:

void clear()
  {
   PARENT::clear();
  }
};
相关文章
|
2月前
|
算法 前端开发 大数据
【C/C++ 基础知识 】C++中易混淆的函数和关键字:std::find vs std::search,std::remove vs std::erase,remove vs delete
【C/C++ 基础知识 】C++中易混淆的函数和关键字:std::find vs std::search,std::remove vs std::erase,remove vs delete
35 0
|
2月前
|
存储 传感器 安全
【C++ std::variant】深入探索 C++ std::variant:构造方法与实践应用
【C++ std::variant】深入探索 C++ std::variant:构造方法与实践应用
81 5
|
2月前
|
存储 安全 程序员
【C++ 包装器类 智能指针】完全教程:std::unique_ptr、std::shared_ptr、std::weak_ptr的用法解析与优化 — 初学者至进阶指南
【C++ 包装器类 智能指针】完全教程:std::unique_ptr、std::shared_ptr、std::weak_ptr的用法解析与优化 — 初学者至进阶指南
71 0
|
4月前
std::vector不隐式拷贝进行添加元素
std::vector不隐式拷贝进行添加元素
|
8月前
|
C++ 容器
【C++】vector中的常见函数和使用
【C++】vector中的常见函数和使用
33 0
|
8月前
|
存储 API C++
C++ std::vector元素的内存分配问题
在使用C++ STL的vector时,下面三种写法有什么不同呢?其内存分配是怎么样的呢? 首先,说结论吧(假设T是一个定义好的类): 对于std::vector<T> vec;这种方式vec在栈上(stack),而其中的元素T保存在堆上(heap); 对于std::vector<T>* vec = new std::vector<T>();这种方式vec和其中的元素T都保存在堆上; 对于std::vector<T*> vec;这种方式vec在栈上(stack),而其中的元素T保存在堆上(heap);和第一种情况类似。
86 0
|
8月前
|
C++
C++11特性之std:call_once介绍
std:call_once是C++11引入的新特性,如需使用,只需要#include <mutex>即可,简单来说std:call_once的作用,确保函数或代码片段在多线程环境下,只需要执行一次,常用的场景如Init()操作或一些系统参数的获取等。
114 0
|
8月前
std::jthread与std::thread区别
std::jthread是C++20新引入的线程类,与 std::thread 类似,或者说,jthread是对thread进一步的封装,功能更强大。
|
9月前
|
存储 容器
2023-3-3-std::array的用法
2023-3-3-std::array的用法
48 0
|
10月前
|
存储 安全 编译器
C++ 中的std::array实现编译器排序
某日二师兄参加XXX科技公司的C++工程师开发岗位第25面: 面试官:array熟悉吗? 二师兄:你说的是原生数组还是std::array? 面试官:你觉得两者有什么区别? 二师兄:区别不是很大,原生数组(非动态数组)和std::array都在栈上开辟空间,初始化的时候需要提供数组长度,且长度不可改变。有一点区别的是,std::array提供了安全的下标访问方法at,当下标越界时会抛出异常。
69 0