template <class Item> class bag { public: //TYPEDEF typedef size_t size_type; typedef Item value_type; ... }
and when I use
template<class Item> bag<Item>::size_type bag<Item>::count(const Item& target) const
VC++ report error as Source.cpp(207): warning C4346: 'bag::size_type' : dependent name is not a type
Could anybody show me why? Thanks!
It should be
template<class Item> typename bag<Item>::size_type bag<Item>::count(const Item& target) const
You need to prepend typename
before bag<Item>::size_type
as it is a dependent type.
typename bag<Item>::size_type bag<Item>::count(const Item& target) const
As per the C++11 Standard:
14.6 Name resolution
A name used in a template declaration or definition and that is dependent on a template-parameter is assumed not to name a type unless the applicable name lookup finds a type name or the name is qualified by the keyword
typename
.
Related: Where and why do I have to put the "template" and "typename" keywords?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With