0
#include<iostream>
#include<cstdlib>
#include<string.h>
using namespace std;
template<typename X>class list
{
    X *l[10];
    public:
        void insert(X *ele);
        void display();
};
template<typename X>void list<X>::insert(X *ele)
{
    static int i;
    l[i]=ele;
    i++;
}
template<typename X>void list<X>::display()
{
    static int i;
    cout<<"\nThe Name #:"<<i<<"\t"<<*l[i]<<endl;
    i++;
}
int main()
{
    string s;
    list<string> l1;
    cout<<"\nEnter Name:\t";
    cin>>s;
    l1.insert();
    l1.display();
    cout<<endl;
    system("pause");
    return 0;
}
1
Contributor
1
Reply
12
Views
3 Years
Discussion Span
Last Post by devourer17
0

I've to create a class template for a list for storing names or numbers. Also i've to use insert, delete and display functions (template functions) for the same. However, the program is throwing an error.
[Error] no matching function for call to 'list<char*>::insert(const char [6])'
Pls help me with this!
Also my concepts when it comes to template class is not much good.F\If u know any good books for the same,pls do share. Taking multiple data members in a template class and using them like the way we use it in a regular class;that's my point of doubt.Thanks in advance

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.