As you know there is a generic class List in .NET framework.
I want to write a generic class List in C++ and i want to store pointers to a type in my list. this is header and source code of class and test program :
// header
template <class Type>
class List
{
public:
List(int size); // constructor
.
.
. // other public members
private:
Type **list; // a dynamic array of pointer to Type
.
.
. // other private members
};
// source code
template <class Type> List<Type>::List(int size) // constructor
{
this->list = new Type[size];
.
. // other parts of definition
}
// main function
void main()
{
List<AnyType> mylist = new List<AnyType>(4);
mylist[0] = new AnyType( // any arguments);
}
it does not work propertly. where is problem ? is it possible to use this class for Structs ?
this->list = new Type[size];should bethis->list = new Type*[size];Edit: did it actually compile? The assignment should at least generate a warning.