Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

templates and friends

0 views
Skip to first unread message

F. P. Beekhof

unread,
Mar 29, 2009, 12:56:55 PM3/29/09
to
Hello,

could anybody tell what I'm doing wrong?

template <typename T, std::size_t D>
class DTree;

template <class is, typename T, std::size_t D>
is& operator>>(is& i_stream, DTree<T, D> &tree);

template <typename T, std::size_t D>
class DTreeProxy
{
public:
template <class is, typename TT, std::size_t DD>
friend is& operator>> (is& i_stream, DTree<T, D> &tree);

private: typedef int Blah;
};


template <class is, typename T, std::size_t D>
is& operator>>(is& i_stream, DTree<T, D> &tree)
{
typedef typename DTreeProxy<T, D>::Blah Blah; // Error
}

The error is then that Blah is private in the operator>>() context.

I'm lost. How should it be done ?

Many thanks in advance,

Fokko Beekhof

litb

unread,
Mar 29, 2009, 1:57:08 PM3/29/09
to

The bug lies here: You have to use DD and TT - not D and T in the
parameter list of the function.

template <class is, typename TT, std::size_t DD>

friend is& operator>> (is& i_stream, DTree<TT, DD> &tree);

As far as i know, it's not possible to declare a friend given a
partial set of template arguments. Either you have to declare
particular instances as friends, or all possible instances of a
template. The above declares all ones as friends. The below declares
one particular instance as friend.

friend istream& operator>> <>(istream& i_stream, DTree<T, D> &tree);

Now, whether the specialization was instantiated or explicitly
specialized - it will be a friend.

0 new messages