Let me guess, you're trying to declare partial specialisations as friends. A weakness in the current standard is you can't do that.
The closest you can come to is something like this;
The down side of this is that it means all instantiations of the template class X are friends of each other - there is no narrowing down to a subset of possible instantatiations of the template as friends.
template <class A, class B, class C> class mad_shared_ptr
// your other stuff
template<class Alpha, class Bravo, class Charlie> friend class X;
For example, you can't replace the friend declaration above with
template<class Alpha, class Bravo> friend class X<Alpha, Bravo, C>;