Topic: Template instantiation question...Is this legal?


Author: mlg@scr.siemens.com (Michael Greenberg)
Date: Mon, 28 Nov 1994 19:38:46 GMT
Raw View
Is this legal?

template <class T>
class Tmpl {
  T _data;
} ;


class my_class {
  Tmpl<my_class>* m1() ;
} ;


If the point of instantiation of Tmpl<my_class> is before the
definition of my_class, then the instantiation will fail because the
size of my_class will not be available at instantiation time.

Does (should) the definition of my_class really require the
instantiation of Tmpl<my_class> when a declaration of Tmpl<my_class>
would suffice?  Is there any reason why the above should be illegal?

Assuming the above is not legal, it is possible to workaround the
problem by declaring Tmpl before the definition of my_class and
defining Tmpl after the definition of my_class (which may not always
be possible).

Thanks,

--
Michael Greenberg                      email: mgreenberg@scr.siemens.com
Siemens Corporate Research             phone: 609-734-3347
755 College Road East                  fax: 609-734-6565
Princeton, NJ 08540