Could you give me an example, please.
Did you mean this?
template <typename T>
class MyList
{
public:
void push_back(const T & t);
template <typename T1>
void emplace_back(const T1 & t);
};
template <typename T>
void MyList<T>::push_back(T const & t)
{
cout << t << endl;
}
template <typename T>
template <typename T1>
void MyList<T>::emplace_back(const T1 & t) // Still in this case we are preceding with "template <type T>", but I don't understand the need of <T> in MyList<T>::
{
cout << "This is another type " << t << endl;
}
int main()
{
MyList<string> obj;
obj.push_back(string("rahul"));
obj.emplace_back(int(23));
}
template <typename T>
class MyList
{
public:
void push_back(const T & t);
template <typename T1>
void emplace_back(const T1 & t);
};
template <typename T>
void MyList<T>::push_back(T const & t)
{
cout << t << endl;
}
template <typename T>
template <typename T1>
void MyList<T>::emplace_back(const T1 & t) // Still in this case we are preceding with "template <type T>", but I don't understand the need of <T> in MyList<T>::
{
cout << "This is another type " << t << endl;
}
int main()
{
MyList<string> obj;
obj.push_back(string("rahul"));
obj.emplace_back(int(23));
}
To copy to clipboard, switch view to plain text mode
Thanks.
Bookmarks