I tired adding T Set::operator[]( int index ) const;
But I keep getting fatal error C1001: An internal error has occurred in the compiler.
1>(compiler file 'msc1.cpp', line 1393)
1> To work around this problem, try simplifying or changing the program near the locations listed above.
1>Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information
Not sure if this is a problem seeing as it currently works now. Thanks heaps.
What compiler are you using????? (Some msoft compiler I can see by the error message).
Without the const method you will not be able to call operator[] on a const Set. (Which might be fine
for what you are doing, but if you are creating a library that others will use, it will be annoying.)
Although I'm not sure what that error message means, it does seem like the error your getting has nothing to do with your code because the compiler message says that it is an internal error. Have you ever tried the Gnu Compiler Collection? g++ is a very nice compiler and I find is more standard compliant than Microsoft's compiler. Try compiling your code with g++ and see if you are getting an error with that. If you are not comfortable compiling on the command line, you can also try the free Code::Blocks IDE, it is completely free and open source and comes set up with g++ as the default C++ compiler.
You can get g++ at www.mingw.org, and Code::Blocks at www.codeblocks.org
Visual C++ 2005 is known to not implement the standard C++ library correctly in a lot of key areas, if you can, try upgrading to the newest version. Visual C++ 2008 is a very good compiler and the Express version is free.
As for your overloads
Try changing:
T Set::operator[]( int index ) const;
to
const T& Set::operator[](int index) const;
Essentially, it does the same thing...but if you ever reuse your library to work with Sets of very large objects (personally, I've had to do collections of objects which take 200mB+ of memory) it is very expensive to return an object by value. If you return a const reference to the object, you do not return of copy of the object but a reference to it but because the reference is const you cannot change the data at that reference. That way you can save yourself a lot of copying time for large objects but still achieve the same const correctness. I'll concede that returning a reference to a primitive value like an int, is probably more expensive than just copying the value...but you are writing a template and the purpose of a template is to be portable and reusable for any data type or class. So I will argue with anyone and everyone that dissagrees that this is the "correct" way to overload that operator.