Questions about a pre-defined piece of code

I hope my question fits the forum and, if it does not, please let me know and I will kindly look for another place to ask.
I have to write a C++ program based on the code below but, as a complete beginner, there are lines of it that I do not understand.
I know that the private part contains the declaration of 2 variables: an integer and a pointer to a char.

Regarding the public segment, I have the following comments:
(1) I do not know what this means.
(2) This is a destructor for the pointer variable.
(3) The function "get_size()" is or must be implemented. What does "const" mean?
(4) The function "is_empty()" is or must be implemented. What does "const" mean?
(5) The function "element_at_rank(int r)" must be implemented. What does "const" mean?
(6) The function "insert_at_rank(int r, const char& elem)" must be imnplemented. What does "const" mean?
(7) The function "replace_at_rank(int r, const char& elem)" must be imnplemented. What does "const" mean?
(8) The function "remove_at_rank(int r)" muest be inmplemented.

This code contains pre-defined (or pre-declared) components of the class "My_vec" that are implemented of that must be implemented. Am I right?

I am a C++ beginner and this assignment is not from a C++ class but from another subject in which we have to write code in this language.

I will very much appreciate your feedback.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  class My_vec {
    private:
      int size, capacity;
      char *ptr;
    public:
      My_vec(): size(0), capacity(10), ptr(new char[capacity]) {} (1)
      ~My_vec() { delete ptr; }                                   (2)
      int get_size() const { return size; }                       (3)
      bool is_empty() const { return size==0; }                   (4)
      char& elem_at_rank(int r) const;                            (5)
      void insert_at_rank(int r, const char& elem);               (6)
      void replace_at_rank(int r, const char& elem);              (7)
      void remove_at_rank(int r);                                 (8)
};

(1) is an constructor with an initialisation list (the preferred way to initialise object variables):
http://www.cprogramming.com/tutorial/initialization-lists-c++.html


What does "const" mean?


This isn't a question for a forum this is basic c++:
http://duramecho.com/ComputerInformation/WhyHowCppConst.html
https://isocpp.org/wiki/faq/const-correctness

edit: damn. beaten to it.
Last edited on
Topic archived. No new replies allowed.