Topic: template declaration


Author: pmaguyot@mon.adresse.est.ailleurs.invalid (Pierre Guyot)
Date: 1999/10/04
Raw View
MW Ron <mwron@metrowerks.com> wrote:

>
> Forward declare one.
>
> template <class> class ClassTwo;
>

Thanks, it compiles fine now. The problem was that CW 4 accepted a
different form of forward declaration.

Thanks,

--
Pierre Guyot
pmaguyot @ free . fr
---
[ 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: Hyman Rosen <hymie@prolifics.com>
Date: 1999/10/01
Raw View
pmaguyot@mon.adresse.est.ailleurs.invalid (Pierre Guyot) writes:
> I need two independent template classes that have to know the existence
> of the other :
> template <class AType>
> class ClassOne {
> ClassTwo< AType>* func1();
> };
> template <class AType>
> class ClassTwo {
> ClassOne< AType>* func2();
> };
> It compiled and worked fine with CW PRO 4, but CW PRO 5 refuses such
> declaration whith "undefined identifier 'ClassTwo'"
> What is the correct way (I've tried so many things :-( ) ?

Just as without templates, you must forward declare a class name
before you can use it:

template <class AType> class ClassTwo;

template <class AType> class ClassOne { ClassTwo<AType> *func1(); };
template <class AType> class ClassTwo { ClassOne<AType> *func2(); };
---
[ 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: mwron@metrowerks.com (MW Ron)
Date: 1999/09/30
Raw View
In article <1dyxmnt.8h5kkilzu074N@[192.168.0.2]>,
pmaguyot@mon.adresse.est.ailleurs.invalid (Pierre Guyot) wrote:

>I need two independent template classes that have to know the existence
>of the other :

Forward declare one.

template <class> class ClassTwo;

template <class AType>
class ClassOne {

ClassTwo< AType>* func1();

};

template <class AType>
class ClassTwo {

ClassOne< AType>* func2();

};

Ron

--
CodeWarrior Pro 5 Review
C++ Report Oct issue, Page 48

METROWERKS                   Ron Liechty
"Software at Work"    MWRon@metrowerks.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: pmaguyot@mon.adresse.est.ailleurs.invalid (Pierre Guyot)
Date: 1999/09/30
Raw View
Hi !

I need two independent template classes that have to know the existence
of the other :

template <class AType>
class ClassOne {
....
ClassTwo< AType>* func1();
....
};

template <class AType>
class ClassTwo {
....
ClassOne< AType>* func2();
....
};

It compiled and worked fine with CW PRO 4, but CW PRO 5 refuses such
declaration whith "undefined identifier 'ClassTwo'"

What is the correct way (I've tried so many things :-( ) ?

thanks,

--
Pierre Guyot
pmaguyot @ free . fr


[ 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              ]