Introduction: . C ++ standards distinguish between character names that depend on template arguments and names that do not have a name called a two-phase name (see here ). Independent names are resolved as soon as possible when you define your template. Dependent names, on the other hand, are only resolved when the template is initialized.
Example:
template<class T> struct Base {
typedef T type;
static const int n = 3;
virtual int f() = 0;
int f(int x) { return x * 2; }
};
template<class T> struct Derived : Base<T> {
type field;
int f() { return n; }
};
I am currently defining Derivedas follows:
template<class T> struct Derived : Base<T> {
typedef Base<T> Parent;
typedef typename Parent::type type;
using Parent::n;
using Parent::f;
type field;
int f() { return n; }
};
For me, one of the main goals of object-oriented programming is to reduce code duplication; this kind of hitting target ...
: Derived, - , ? - :
template<class T> struct Derived : Base<T> {
using Base<T>::*;
type field;
int f() { return n; }
};
. : , . , typedefs/fields/functions Base 5 . , typedefs using , , , .
, !