Hello Guys,
Thw following program is giving an error. Is the program incorrect (If
possible, please cite relevant sections from the C++ standard)? Should I
file a bug?
% /usr/local/gcc-4.0.0/bin/g++ template.cxx
template.cxx: In function 'T<X>* func(T<Y>*) [with X = B, Y = A]':
template.cxx:36: instantiated from here
template.cxx:21: error: 'A* T<A>::m_' is private
template.cxx:30: error: within this context
// Line 1
class A {
public:
A() { };
~A() { };
};
class B {
public:
B();
B(const A& a) { };
~B();
};
template <typename X> class T;
template <typename X, typename Y>
T<X>* func(T<Y>* p);
template <typename X> class T {
X* m_;
public:
T(X* x) : m_(x) { };
~T() { };
friend T<class Y>* func<Y, X>(T<X>* p);
};
template <typename X, typename Y>
T<X>* func(T<Y>* p) {
return (new T<X>(new X(*p->m_)));
}
int main() {
A* a = new A();
T<A>* p = new T<A>(a);
T<B>* q = func<B, A>(p);
return 0;
}
Best Regards,
Shelly