Re: Compiler problem or feature?
Unfortunately, there is no way of declaring a template class as a friend of another class. Something like this is not allowed:
class A
{
template <typename T> friend class B;
};
I'm not sure, but try something like (if I remember well, IsOdd should be a friend of class J, and is declared inside the class J):
friend typename IsOdd;
Re: Compiler problem or feature?
The thing you said is not allowed is used in boost's shared pointers. However they have disabled it for many compilers, including Visual C++.
It seems the best solution is to ensure the functor only calls public methods. There is another workaround, which I don't like, and that is to make the member private in the inner class and make the friendship the other way. Then the outer class will need an instance of the inner class, (maybe with K=void or void*/int if it won't compile with void)
The best things come to those who rate
Re: Compiler problem or feature?
I think avoiding using friend classes and function is a good strategy.
I work with Visual C++ and I know there are some standard things not supported. Some missing features made me write some equivalent ugly code (for example, partial template specialization).
Re: Compiler problem or feature?
in general I prefer not to use friends, but I often use them for inner (nested)classes because that does not lead to any more dependencies than were there before.
Usually the inner class is there to implement some feature of the class (as in my case) and is therefore a relevant part of it.
Similarly, you may want the inner class to be public to the outside, but only in part. However you may want your outer class to have access to the full detail. If you put in public access functions, others can call them just as well as your outer class.
By the way, a lot of people's favourite model is faulty:
class MyInterfaceImpl;
//
class MyInterface
{
public:
// all my public functions here
private:
MyInterfaceImpl * m_pImpl;
};
This is faulty because generally m_pImpl is created with new in the constructor and deleted with delete in the destructor.
In that case, you have to either put in a deep copy constructor and assignment operator or disable them altogether by making them private.
The best things come to those who rate