我该如何制作这个节目? (C ++运算符) [英] How can I make this program? (C++ operator)

查看:91
本文介绍了我该如何制作这个节目? (C ++运算符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// my_list.hpp

template<class T> class MyList {
private:
    T* items; // an array of items.
public:
    MyList();
    ~MyList();
    operator+=(T&); // Adds a new item at the end.
    operator+(T&); // Adds a new item at the beginning.
    operator+(MyList<t> l&); // append the content of "l" at the end of your list.
    operator=(MyList<t> l&); // copy the list "l" into your list and removes the existing items.
    T& operator[](int)  // returns an item located at a desired position.
    T front();     // Returns a copy of the first element in the list
    T back();       // Returns a copy of the last element in the list
    push_front(T& g);    // Adds a new element ‘g’ at the beginning of the list
    push_back(T& g);     // Adds a new element ‘g’ at the end of the list
    T pop_front();    // Removes the first element of the list, and reduces size of the list by 1
    T pop_back();     // Removes the last element of the list, and reduces size of the list by 1
    T* begin();     // Returns a pointer of the first element of the list
    T* end();       // Returns a pointer of the last element of the list
    bool empty();   // Returns whether the list is empty(1) or not(0)
    insert(int pos, T&);  // Inserts new elements in the list before the element at a specified position
    erase(int pos);   // Removes a single element at a position
    reverse();            // Reverses the list
    size_t size();  //Returns the number of elements in the list

};





我的尝试:



如何我可以制作一个节目吗?你的想法是什么?



What I have tried:

How can I make a program ? what's your ideas?

推荐答案

Quote:

我该如何制作一个节目?

How can I make a program ?

编码,当然。



Coding, of course.

引用:

你的想法是什么?

我的想法是:这是家庭作业(否则你可能已经使用了正确的STL容器),所以这取决于你:从一个非常简化的界面开始(即注释掉大多数方法声明)并实现它。当你遇到困难时,请在这里询问具体的帮助。

My idea is: this is homework (otherwise you could have used the proper STL container), so it is up to you: start with a very simplified interface (that is comment out most of the method declarations) and implement it. Ask here for specific help whenever you are stuck.


首先你需要学习C ++ 一些教程。



非常重要:你的阵列需要一些动态内存管理。 本教程正在帮助您理解这一点。



然后实现你的家庭作业的空体,并填写一些代码。为你的功能编写测试!!!
At first you need to Learn C++ by some tutorial.

Very important: you need some dynamic memory managment for your array. This tutorial is helping you to understand that.

Then implement the empty body of your homework and fill it with some code. Write tests for your functions!!!


这篇关于我该如何制作这个节目? (C ++运算符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆