Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override operators for an existing class

Tags:

c++

oop

I am after two things. I first want to typedef the vector class to something a little more meaningful such as List. I tried the following but it gave me a compile error:

template <typename T>
typedef vector<T> List<T>

Secondly I want to override the << operator of the vector class, but I have no idea how I would go about it without creating a new class.

This may seem counter-productive but my end aim is to have something that non-programmers (or people that haven't done c++ before) can read that makes semantic sense.

like image 319
Cheetah Avatar asked Dec 21 '22 23:12

Cheetah


1 Answers

If you do this, non-programmers still will be unable to read, let alone change, the code. However, C++ programmers will also have a lot of trouble reading the code.

If they cannot code, and need a C++ programmer to code it for them, then they will need a C++ programmer to understand, maintain, and extend the code which that first C++ programmer has written.

If, OTOH, they need to code in C++, then — surprise! — they will have to learn to write and read C++ code.

There really is nothing in between.

like image 136
sbi Avatar answered Dec 24 '22 02:12

sbi