More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions

I l @ ve RuBoard

Difficulty: 7

"What's in a (type) name ?" Here's an exercise that demonstrates why and how to use typename , using an idiom that's common in the standard library.

  1. What is typename , and what does it do?

  2. What, if anything, is wrong with the code below?

    template<typename T> class X_base { public: typedef T instantiated_type; }; template<typename A, typename B> class X : public X_base<B> { public: bool operator()( const instantiated_type& i ) const { return i != instantiated_type(); } // ... more stuff ... };

I l @ ve RuBoard

Категории