c++ - How to pass a reference of template reference into class method?
问题描述
I have been working on this problem for a few days and can not find a solution to my problem online. The problem given to me was to create an insert and erase method for a vector class. The method headers were given to me as iterator insert(iterator pos, const Object& x);
and iterator erase(iterator pos);
. When I made a vector class everything compiled without errors other than never being used. the code is as follows.
template<typename iterator, typename Object> class Vector
{
public:
iterator insert(iterator pos, const Object& x)
{
element[pos] = x;
}
iterator erase(iterator pos)
{
element[pos] = '\0';
}
private:
iterator pos;
Object element;
};
The main function looks like this:
int main()
{
Vector<int, class Object> myVec;
int i = 9;
myVec.insert(0,i);
}
After I finished that the only error occors on the line Object element
line. With the error message "Field has incomplete type 'Object'". I apologize if this is very simple to fix but I am new to iterators and vectors so to have to create the methods myself is confusing. All help is appreciated, thank you.
解决方案
推荐阅读
- java - 使用 H2 db 模拟 Jdbctemplate 会出错
- php - phpunit 没有在 laravel 中运行
- php - Yii 1 Pagination 在不同的控制器中显示不同的行为
- vue.js - vue.js 导入的模块在承诺回调中未定义
- python - 如何修复:ValueError:输入 0 与层 lstm_2 不兼容:预期 ndim=3,发现 ndim=2
- java - 如何计算多个纬度和经度之间的距离?
- excel - 取消保护所有没有密码的工作表
- c# - 如何根据孩子获取windows消息?
- javascript - 如何在Angular 8中将属性从父组件传递给子组件?
- c++ - 创建相机来旋转立方体不起作用