Topic: friends, privates and templates
Author: Marc Girod <girod@stybba.ntc.nokia.com>
Date: 1998/05/06 Raw View
>>>>> "JV" == John M Vreeland <jmvree@infi.net> writes:
JV> But I could not figure out a way to forward declare it.
JV> "template <class T> B<T>;" was rejected.
Then try:
template <class T> class B;
--
Marc Girod Valimo 1/2 Voice: +358-9-511 63331
Nokia Telecommunications P.O. Box 315 Mobile: +358-40-569 7954
NWS/NMS/NMS for Data 00045 NOKIA Group Fax: +358-9-511 63310
Finland marc.girod@ntc.nokia.com
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "John M. Vreeland" <jmvree@infi.net>
Date: 1998/05/04 Raw View
I get different results from different compilers with this one. I hope
these examples are correct and to-the-point .
**********
//forward dec
class B;
template <class T>
class A {
public:
T object;
friend class B; //tried both of these
//friend class B<T>;
private:
struct PrivateStruct{T * something;};
};
template <class T>
class B {
private:
A::PrivateStruct localCopy; // <<--Problem here
};
********
This works just fine in the g++ code I have, but chokes when I try to
port it to Borland 5. Borland claims I do not have access to the
private members of A, so what was the "friend" for? I know that Borland
occasionally blunders, but the G++ I am using can barely handle
templates, and forget about the standard lib.
"friend B<T>;" would not work because it had not been forward
declared. But I could not figure out a way to forward declare it.
"template <class T> B<T>;" was rejected.
Please note that I hate using "friend" for anything but global
operators. My task is just to port this monster, not re-write it.
Tempting, though. :-P
-John M. Vreeland
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: martelli@cadlab.it (Alex Martelli)
Date: 1998/05/05 Raw View
"John M. Vreeland" <jmvree@infi.net> writes:
[how to forward-declare a template class]
I think the following should work:
template <class T> class B;
template <class T> class A {
public:
friend class B<T>;
private:
struct pip { T* pop;} ;
};
template <class T> class B {
A<T>::pip pup;
};
and indeed it compiles just fine on MS VC++5.0 SP3.
Alex
--
____ Alex Martelli, Bologna, Italia -- email: alex@magenta.com
\SM/___ http://magenta.com/~alex
\/\bi/ You never know what is enough unless you know what
\/ is more than enough.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]