[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | C++ |
Notice: | Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS) |
Moderator: | DECCXX::AMARTIN |
|
Created: | Fri Nov 06 1987 |
Last Modified: | Thu Jun 05 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 3604 |
Total number of notes: | 18242 |
3481.0. "Deriving nested class from template don't automatically instantiate it" by NETRIX::"[email protected]" (Goedtler Peter) Mon Mar 10 1997 09:56
Hi,
we are working on a C++ project at a customer and we are often using
templates.
Beside all other troubles when providing a class library with templates for
other engineering teams, the newest 'feature' occurs with nested template
classes:
The template class Enclosed<T> contains the class Nested which inherits from
another template class Super<T>. The super class defines a pure virtual
function trouble() which has to be implemented by the subclasses (here:
Nested).
Unfortunately, it does not work implementing the function unless it is
real inline.
//Template superclass for the nested class below
template<class T>
class Super
{
public:
Super() {};
virtual void trouble()=0;
};
//
// Template class with a nested class
//
template<class T>
class Enclose
{
public:
Enclose() {};
class Nested : Super<T>
{
public:
Nested() : Super<T>() {};
// Does not work
void trouble();
// This would work, because it's inline
// void trouble() { cout << "No trouble" <<endl;};
};
};
//
// Does not work
//
template<class T>
void Enclose<T>::Nested::trouble()
{ cout << "Trouble" << endl; }
//
// Test class used for template instantiation
//
class Hello
{
public:
Hello(){};
};
main()
{
Enclose<Hello> hi;
}
We are using DEC C++ 5.5-010 on Digital UNIX (Alpha) 4.0. I compiled and
linked with:
cxx -o test_nested test_nested.cxx
ld:
Unresolved:
__vtbl_16Enclose__T5Hello6Nested Make sure that the first noninlined virtual
member function of 'Nested' is defined.
Do we need to implement all methods of nested template classes inline??
I don't hope.
Thanks
Peter
[Posted by WWW Notes gateway]