Hello,
I used to code in python and I recall being able to take a class such as the list class and add my own functions to it. I am not quite sure what this is called in c++ or how to do it, so I was just wondering if some one could point me in the right direction with an article, tutorial, or at least what it is called for C++.

Thank you
~Blitze

I can't seem to find an article that displays the syntax for adding functions to a std class in c++ such as an array or vector... is there a way to do that?

Im not actually sure if you can inherit from the std library, but if you were able to,

class MyClass : public vector
{
}

The colon is the inheritance operator, but like i said, Im not sure if you are able to inherit and how it works with templated classes. Essentially, all the vector class is, is a linked list. You could build a class that can do what the vector can do and more fairly easily if you know how to handle pointers.

http://www.cprogramming.com/tutorial/lesson19.html
there is a second part after the first page that helps explain with a syntax example.

Edited 6 Years Ago by LevyDee: n/a

>>all the vector class is, is a linked list
Are you implying that a std::vector class is implemented using a linked list data structure?

Example :

template<typename T>
class SpecialList : std::list<T>{
public:
 //add functionalities here
};

Or use composition :

class SpecialList{
 private: std::list<int> listOfInts;
 public: 
  void push_back(int i){ listOfInts.push_back(i); }
  //..more list functions, delegate the job to list;
  //add your functionalities here.
};

Edited 6 Years Ago by firstPerson: n/a

Ive never opened up and took a look at the header file, but the functionality it provides, seems very similar to a linked list data structure. I could be wrong, but that's sort of how I see it.

Yea, sorry to tell you but std::vector is based on arrays not linked list. It provides those functionalities to be consistent.

Alright, I will look into it. Thank you all for the suggestions, I appreciate it. I will be attempting to do it over the weekend so I'm not sure how it will go just yet..

Edited 6 Years Ago by Blitze: n/a

This question has already been answered. Start a new discussion instead.