Как избежать повторения имени класса и вызова шаблона в реализации?

Я нахожу приведенный ниже код ужасно трудным для чтения, и я написал его! Есть ли способ

  1. избежать вызова шаблона для каждой реализованной функции-члена
  2. , чтобы избежать наличия ClassName :: member_function_name для каждой реализованной функции-члена? В этом отношении я считаю Java DRYer. Имя класса не повторяется везде.

Спасибо!

template <class KeyType, class ObjectType>
class Vertex
{
private:
    KeyType key;
    const ObjectType* object;
public:
    Vertex(const KeyType& key, const ObjectType& object);
    const KeyType getKey();
};

template <class KeyType, class ObjectType> 
class Graph
{
private:
    map<KeyType, Vertex<KeyType, ObjectType> > vertexes;
public:
    const Vertex<KeyType, ObjectType>& createVertex(const KeyType& key, const ObjectType& object);
};

template <class KeyType, class ObjectType>
Vertex<KeyType, ObjectType>::Vertex(const KeyType& objectKey, const ObjectType& newObject)
{
    key = objectKey;
    object = &newObject;
};

template <class KeyType, class ObjectType>
const KeyType Vertex<KeyType, ObjectType>::getKey()
{
    return key;
};

template <class KeyType, class ObjectType>
const Vertex<KeyType, ObjectType>& Graph<KeyType, ObjectType>::createVertex(const KeyType& key, const ObjectType& object)
{
    Vertex<KeyType, ObjectType> *vertex = new Vertex<KeyType, ObjectType>(key, object);
    vertexes.insert(make_pair(vertex->getKey(), *vertex));
    return *vertex;
};
5
задан MByD 5 April 2011 в 00:46
поделиться