I think you are missing something. The way that i can think of specialized template where if
T (in my case) is not double , then do something like this on the print method
template <typename T> void MyQueue <T>::Print()
{
std::vector <double>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout << " " << *It1<<endl;
}
template <> void MyQueue<long>::Print()
{
std::vector <long>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout << " " << *It1<<endl;
}
template <> void MyQueue<int>::Print()
{
std::vector <int>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout << " " << *It1<<endl;
}
template <> void MyQueue<bool>::Print()
{
std::vector <bool>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout <<std::boolalpha << *It1<<endl;
}
template <typename T> void MyQueue <T>::Print()
{
std::vector <double>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout << " " << *It1<<endl;
}
template <> void MyQueue<long>::Print()
{
std::vector <long>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout << " " << *It1<<endl;
}
template <> void MyQueue<int>::Print()
{
std::vector <int>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout << " " << *It1<<endl;
}
template <> void MyQueue<bool>::Print()
{
std::vector <bool>::iterator It1;
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout <<std::boolalpha << *It1<<endl;
}
To copy to clipboard, switch view to plain text mode
but now I want to extract the real printing itself and have just one method that will do this
// this is the real printing part
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout <<std::boolalpha << *It1<<endl;
// this is the real printing part
It1 = data.begin();
for ( It1 = data.begin( ) ; It1 != data.end( ) ; It1++ )
cout <<std::boolalpha << *It1<<endl;
To copy to clipboard, switch view to plain text mode
how can i have just one method to do all this on all type of T
baray98
Bookmarks