简体   繁体   English

C ++向量pushback()和popback()函数

[英]c++ vector pushback() & popback() functions

I have a vector and would like to write my own functions for school purposes and im stuck. 我有一个向量,想写我自己的函数用于学校目的,并且卡住了。

void push_back(int value)
void pop_value();

i would like to implement functions in main like this 我想像这样主要实现功能

iv2.push_back(100)
iv2.push_back(101) // will cause exception to be thrown.

can someone please show me how to write these functions out so i can understand what they are doing. 有人可以告诉我如何将这些函数编写出来,以便我了解它们在做什么。 Let me know if you need more of my class. 让我知道您是否需要更多我的课程。

class int_vector {


public:
        //deafault constructor
        int_vector() : capacity_(minCapacity_), size_(0), data_(new int[capacity_]) {
            cout << "default constructor of: " << this << "\n";
        }

...


private:


void push_back(int value) {}?
void pop_value(){}

....

You can look at how a vector is implemented at https://github.com/lnishan/vector/blob/master/vector.hpp 您可以在https://github.com/lnishan/vector/blob/master/vector.hpp上查看如何实现矢量

I hope it helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM