Original Post
Hi, i'm working on a dynamic Array for my "little" game engine on C++ & DirectX, my array class uses a template and has an interface similar to this definition: class CArray { private: T *ptrT; public: operator const T *() const { return ptrT; } T &operator[](unsigned i) const { ... return *(ptrT + i); } ... } The first overload, a cast to T* overload, is trying to give a more flexible and "compatible" type. For example, many functions from STL that uses strings as parameters would specified a char pointer, so if T = char, then i can use this explicit cast overloading to call any of this functions with my own CArray variables as parameters. The second overload is the intuitive index call for any vector, where parameter i returns a reference to the element in the i-position of the array. And now, the problem, the compiler throws this error, at the first call of the operator []: "error C2666: '[]' : 2 overloads have similar conversions" I know that the ptrT index to the first element of the array, that is the same as ptrT[0], but this idea seams not to be working for my class in the [] overloading. For example, if i comments the first overload (operator const T *() const...), and try: CArray string; char *ptrChar = string; or CArray to; CArray from; strcpy(to, from); ... Compiler shows this error: "cannot convert from 'class CVector' to 'char *'" (what i was trying to avoid or solve at the beginning with the overloading: "operator T *() const...", so i don't know ¿???). ... finally i can't use my own type directly over any other API function or just give my own library a sort of "independency" or reusability... :( I hope you can help, giving me a clue or any other different way to obtain the same functionality with the array. PD: I'm using this 2 overloads operators with the exactly syntax as Daitel made it in his book, but unfortunaly, he never use both together in any example... e-milio