I have created a SinglyLinkedList
template class using template <class T>
. For example, if I enter "string" as my command line argument, I want to create SinglyLinkedList<string>* string_list = new SinglyLinkedList<string>();
. If I enter "number" as my command line argument, I want to create SinglyLinkedList<string>* number_list = new SinglyLinkedList<string>();
.
Is there a way that I can combine this in order to do something along the lines of:
SinglyLinkedList<>* list;
if (argv[0] == "string") {
list = new SinglyLinkedList<string>();
} else if (argv[1] == "number") {
list = new SinglyLinkedList<int>();
}
If I do this now, the first line throws an error invalid template code
.
Is there a way to do this in C++11?