Providing declarations when declaring the template

Carbide.c++ processes any declarations in a template when the template is declared, not when it is instantiated.

Although the C++ compiler currently accepts declarations in templates that are not available when the template is declared, future versions of the compiler will not. Listing 1 shows some examples.

Listing 1. Declarations in Template Declarations

// You must define names in a class template declaration

struct bar;
template<typename T> struct foo {
bar *member; // OK
};
struct bar { };
foo<int> fi;

// Names in template argument dependent base classes:

template<typename T> struct foo {
typedef T *tptr;
};

template<typename T> struct foo {
typedef T *tptr;
};
template<typename T> struct bar : foo<T> {
typename foo<T>::tptr member; // OK
};

// The correct usage of typename in template argument
// dependent qualified names in some contexts:

template<class T> struct X {
typedef X *xptr;
xptr f();
};
template<class T> X<T>::xptr X<T>::f() // 'typename' missing
{
return 0;
}

// Workaround: Use 'typename':

template<class T> typename X<T>::xptr X<T>::f() // OK
{
return 0;
}