TNT Array2D

Aug 19, 2011 at 8:49am
Hi all,
This is a part of the header file of the TNT 2DArray class:
1
2
3
4
5
6
7
8
9
10
template <class T>
class Array2D
{
-Data
-Many more methods and these two:

T* 	operator[] (int i)
const T* 	operator[] (int i) const

}

I don't understand the difference between the two operators, how can the computer realize the two and overloading them? Can you give me a help?
Thank you very much.
Aug 19, 2011 at 9:01am
In one, the this pointer is constant. Since it is an implicit first parameter, the two functions can be overloads.
Aug 19, 2011 at 9:15am
Thank you, Zhuge.
Could you give me an example of the two calls? I am still not so familiar with thinking in C++...
Aug 19, 2011 at 9:26am
Sure.
1
2
3
4
5
Array2D<int> Array;
const Array2D<int> ConstArray;

Array[0]; // calls the line 7 operator
ConstArray[0]; // calls the line 8 operator 
Aug 19, 2011 at 9:32am
Thank you very much, I get the point!
Topic archived. No new replies allowed.