S.S S.S - 1 year ago 56
C++ Question

Overloading C++ subscript [] operator with long int index possible?

In every example I only see

as the argument for indexing the array:

unsigned char& operator[](int i)

I wonder if this is possible?:

unsigned char& operator[](__int64 i)

I would like to create an array like class, where I could access the entire address space of a given process as an array, which can be larger then 4GB (32bit) on a 64 bit OS.

Answer Source

Yes, you can use any type you want, although __int64 may not be the most portable choice. Try std::int64_t or std::uint64_t instead (or size_t/ptrdiff_t).

If you want examples with different types than int look no further than std::vector and std::map.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download