Hi,
I'm trying to learn templates. I want to pass strings and integers via objects. I made it as a template because my program should support both strings and integers.
// Main Function
int main()
{
string element;
library <string> comics;
cout << "\nPlease type in the element: \n";
cin >> element;
comics.insert(element);
return 0;
}
Header file as follows
// header file
template <class T>
class library {
private:
vector <T> v;
int sort_status;
int list_size;
int duplicate;
public:
//Public member functions
Booklist(){
sort_status=0;
list_size=0;
duplicate=0;
}
void insert(T const&);
};
// Function definition for adding new element to the end of the list
template <class T>
void library <T>::insert(T const& new_element){
v[0] = new_element;
list_size++;
}
What am i doing wrong? Program compiles but when i enter a string as input, i get this error.
(lldb) EXC_BAD_ACCESS
Any help would be appreciated. Thanks