B
barcaroller
This is a follow-up to a previous post ("Templates: separating interface
from implementation", July 14)
My current GNU C++ compiler does not allow me to separate template
interfaces from the implementation. This seems to be the norm, according to
the documentation.
However, I dug up some old C++ I had written in the mid 1990's and, sure
enough, the template code is neatly separated into *.h and *.cpp files.
This code used to compile under Sun C++ on Solaris/SPARC and HP C++ on
HP-UX/PA-RISC. Is my memory playing tricks on me or has this particular
template behaviour changed over the last 15 years?
I have provided a snippet below (but I have a lot more examples, all written
in the early-to-mid 1990s).
tree.h
======
template<class T>
class tree
{
public:
...
Node<T>* AddFirstChild(Node<T>* newkid, Node<T>* parent);
...
tree.cpp
========
template<class T>
Node<T>* tree<T>::AddFirstChild(Node<T>* newkid, Node<T>* parent)
{
newkid->sibling = parent->firstchild;
parent->firstchild = newkid;
newkid->parent = parent;
return newkid;
}
from implementation", July 14)
My current GNU C++ compiler does not allow me to separate template
interfaces from the implementation. This seems to be the norm, according to
the documentation.
However, I dug up some old C++ I had written in the mid 1990's and, sure
enough, the template code is neatly separated into *.h and *.cpp files.
This code used to compile under Sun C++ on Solaris/SPARC and HP C++ on
HP-UX/PA-RISC. Is my memory playing tricks on me or has this particular
template behaviour changed over the last 15 years?
I have provided a snippet below (but I have a lot more examples, all written
in the early-to-mid 1990s).
tree.h
======
template<class T>
class tree
{
public:
...
Node<T>* AddFirstChild(Node<T>* newkid, Node<T>* parent);
...
tree.cpp
========
template<class T>
Node<T>* tree<T>::AddFirstChild(Node<T>* newkid, Node<T>* parent)
{
newkid->sibling = parent->firstchild;
parent->firstchild = newkid;
newkid->parent = parent;
return newkid;
}