Topic: Q: Inner template instantiation
Author: "Scott Robert Ladd" <scottrobertladd@hotmail.com>
Date: Wed, 6 Sep 2000 18:29:15 GMT Raw View
The following code is (in my mind, at least) valid and should not generate
any errors:
#include <iostream>
#include <iomanip>
using namespace std;
template <typename T>
class Outer
{
public:
class Inner
{
public:
Inner();
};
};
template <typename T>
Outer<T>::Inner::Inner()
{
cout << "Inner constructor" << endl;
}
template <typename T>
class Derived : public Outer<T>::Inner
{
public:
Derived();
};
template <typename T>
Derived<T>::Derived()
: Outer<T>::Inner()
{
cout << "Derived constructor" << endl;
}
int main()
{
Derived<int> obj;
return 0;
}
Contrary to *my* beliefs, however, Visual C++ 6.0 SP3 complains that
Outer<int>::Inner::Inner() is an unresolved external reference.
Curiously, the above code compiles and links if I move the definition of
Outer<int>::Inner::Inner() inside the class declaration (as opposed to
defining it externally, as I have above). The code also compiles if the
classes are not defined by templates.
So is my code correct and Visual C++ wrong (my theory) -- or is there some
subtle secret about deriving from classes declared inside templates?
- Scott Robert Ladd
---
[ 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 ]