Reputation: 51
Which of the following syntaxes is preferred or is legally correct:
template< class T >
struct S
{
typedef std::vector< S > V;
// typedef std::vector< S< T > > V;
Visual C++ and gcc accept either but C++Builder XE3 reports a "E2299 Cannot generate template specialization" error on the first.
Upvotes: 2
Views: 301
Reputation: 157344
Both are correct; the class name is injected into the scope of the class: What feature of C++ lets template classes refer to themselves without template arguments?
The feature is used occasionally; for example, the Standard uses it in its specification of the Standard library, for conciseness. You might consider avoiding it in your own code for the sake of clarity.
Upvotes: 7