devxlogo

Use typedefs when the Template Parameter List Contains Another

Use typedefs when the Template Parameter List Contains Another

Suppose you have the class given below:

 #include #include std::list<:pair>> list_of_pairs;

In the above definition, the template argument for list is another template class namely, pair. The above definition won’t compile. For ex, VC++ 6.0 gives the following error:

 syntax error : missing ',' before identifier 'list_of_pairs'

The correct way to declare the above is by using a typedef as given below:

 typedef std::pair int_pair;std::list list_of_pairs;

devx-admin

Share the Post: