The vector class provides access and altering uses brackets, e.g. v[5]. How can I make a class that can do the same? e.g. given Class Test object t, t[5]=...
Kadence
0
Light Poster
Recommended Answers
Jump to PostHere is a simple example. You need to overload the [] operator, as below.
const int MAXSIZE = 20; class MyClass { public: MyClass() { x = 0; for(int i = 0; i < MAXSIZE; ++i) array[i] = i+1; } int& operator[](int n) {return array[n];} private: int …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.