template <class T>
class myclass {
public:
...
myclass(int i) : m(i) {}
template <class U> myclass(const myclass<U>& rhs);
...
private:
int m;
};
template <class T> template <class U>
myclass<T>::myclass(const myclass<U>& rhs) : m(rhs.m) {
}
...
int main() {
myclass<int> x(1);
myclass<float> y(x);
}
error: ‘int myclass<int>::m’ is private
error: within this context - line of initialization list in the 2nd myclass constructor
Adding the following doesn't help:
template <class U> friend class myclass<U>;
Is there any way to make all type instantiations of myclass become friends with each other?