This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
gcc template error?
- From: Shelly Adhikari <shelly at interrasystems dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 22 Jun 2005 10:56:42 -0700
- Subject: gcc template error?
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