Kvothe
Kvothe

Reputation: 477

Multi parameter template not playing nicely with friend declaration

The following snippet works fine in both Visual Studio and g++.

template<typename T> class BST;

template<typename T>
class BSTNode 
{
    friend class BST<T>;
...

while this snippet works fine in VS, but not g++

template<typename K, typename V> class Map;

template<typename K, typename V>
class MapPair
{

    friend class Map<typename K, typename V>;
     ...

What is wrong with this code? The errors I get are unhelpful, but here they are

error: wrong number of template arguments (1, should be 2)
error: provided for ‘template<class K, class V> struct Map’
error: friend declaration does not name a class or function

Any ideas?

Upvotes: 1

Views: 130

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477444

Say friend class Map<K, V>;. typename may only be used to qualify dependent names, which K and V are not.

Upvotes: 1

Related Questions