Y
ymost
Hi,
I have a class template with two template arguments. It contains a
private nested class, and I want a non-member function to return an
instance of the nested class:
//-----------------------------------------------------------------
template<typename T1,typename T2> class A {
class B {};
};
template<typename T> typename A<T,T>::B func(T x){};
int main() {
A<int,int> aii;
A<double,double> add;
A<int,double> aid;
A<double,int> adi;
func(1);
return 0;
}
//----------------------------------------------------------------
(I created some instances of A with different types for testing).
Naturally I'm getting a 'class a<int, int>::B is private' error, but I
simply cannot succeed in making func a friend function of the class
template A. Each reference to func inside the class template A
(whether it's a friend declaration or the whole function definition)
causes either multiple ambiguous declarations of func, or an access
violation because the different instances of A are not friends of each
other (at least I think that's the reason).
Help will be appreciated.
Thanks
I have a class template with two template arguments. It contains a
private nested class, and I want a non-member function to return an
instance of the nested class:
//-----------------------------------------------------------------
template<typename T1,typename T2> class A {
class B {};
};
template<typename T> typename A<T,T>::B func(T x){};
int main() {
A<int,int> aii;
A<double,double> add;
A<int,double> aid;
A<double,int> adi;
func(1);
return 0;
}
//----------------------------------------------------------------
(I created some instances of A with different types for testing).
Naturally I'm getting a 'class a<int, int>::B is private' error, but I
simply cannot succeed in making func a friend function of the class
template A. Each reference to func inside the class template A
(whether it's a friend declaration or the whole function definition)
causes either multiple ambiguous declarations of func, or an access
violation because the different instances of A are not friends of each
other (at least I think that's the reason).
Help will be appreciated.
Thanks