0

If I have

namespace A
{
        template<class T>
        inline void SomeFunc(T& archive, Object* object)
        {
            // ...
        }
}

and a non-template class

namespace B
{
    class Manager
    {
        // ...
        template <typename T, typename U> friend void A::SomeFunc(T& t, U* u);
    };
}

why doesn't class Manager recognize A::SomeFunc() as a friend?

What I'm trying to do: I'm gonna have a good number of these SomeFuncs, all taking different U classes (which derive from the same base), so I was looking for a clean way to do it without befriending tons of these functions.

Kristian D'Amato
  • 3,996
  • 9
  • 45
  • 69

1 Answers1

2

The number of template arguments matter. You are befriending a template that takes two template arguments, but the real template has only one. They are different entities.

Your friend declaration should be:

template<class T>
friend void SomeFunc(T&, Object*);
David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489
  • Makes sense. Thing is I'm gonna have a good number of these `SomeFunc`s, all taking different `U` classes (which derive from the same base), so I was looking for a clean way to do it. Until now, I don't have a solution. – Kristian D'Amato Nov 21 '13 at 08:23
  • @KristianD'Amato: The need for friendship is rare. Needing to befriend many different functions is even rarer. Maybe you could take a look at your design and refactor it. – David Rodríguez - dribeas Nov 21 '13 at 14:13
  • Yes, you're right. I protected the constructors to control object creation, but I guess that's gonna remain a fantasy. – Kristian D'Amato Nov 21 '13 at 16:20