Topic: Conversion of pointers used as template parameters, from derived to base


Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1999/06/29
Raw View
On Jun 26, 1999, "Jeff Greif" <jmg@spam-me-not.trivida.com> wrote:

> Is it legal according to the standard?

Nope, it's explicitly forbidden in [temp.arg.nontype]/5, subitem 2.

> Is there some other way to express it?

I don't think so.

> Various kinds of casts in the typedef Ht<T,p> ht; line were
> attemped, but none could be parsed by the compiler

A template argument can't be the result of a type cast not involving
integral types.

--
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
{oliva,Alexandre.Oliva}@dcc.unicamp.br  aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
*** E-mail about software projects will be forwarded to mailing lists
---
[ 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: "Jeff Greif" <jmg@spam-me-not.trivida.com>
Date: 1999/06/26
Raw View
One compiler accepts this, but another does not, complaining about being
unable to convert d1 to a BaseFun<T>* in compiling class M.  Is it legal
according to the standard?  Is there some other way to express it?  Various
kinds of casts in the typedef Ht<T,p> ht; line were attemped, but none could
be parsed by the compiler which rejected the code as it is below.

-----------------------------------------------------------------------
template <class X> class BaseFun {};

template <class X> class DerivedFun1 : public BaseFun<X> {};

template <class T, BaseFun<T> *p> class Ht {};

template <class T, DerivedFun1<T> *p> class Hm {
private:
  typedef Ht<T,p> ht;
  ht rep;
public:
  Hm() {}
};


DerivedFun1<int> d1;

class M : public Hm<int, &d1> {};
---
[ 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              ]