I am instantiating an iterator within a method in one of my templates. It works when I use auto
to dynamically obtain type information:
auto itr = my_list.cbegin();
However, I get a compile-time error when I use the actual type:
typedef InternalEdge network_internal_edge_type;
typedef std::shared_ptr< network_internal_edge_type > network_shared_edge_ptr;
typedef std::list< network_shared_edge_ptr > network_internal_edge_store_type;
network_internal_edge_store_type::const_iterator itr = internal_edges_.cbegin();
InternalEdge
is a private class I had defined somewhere above in the code.
Here is the error:
Network.hpp:411:5: error: need ‘typename’ before ‘Network<V>::internal_edge_store_mechanism:: const_iterator’ because ‘Network<V>::internal_edge_store_mechanism’ is a dependent scope
Network.hpp:411:46: error: expected ‘;’ before ‘itr’
Network.hpp:412:12: error: ‘itr’ was not declared in this scope
Why does using auto
make the code work? Why does the compiler think I need "typename"?