Это должно быть «почти» эквивалентно вашему коду. «почти», потому что, как сказал xDD, внутреннее определение функции-члена неявно помечает их как встроенные.
Класс по умолчанию закрытый, а Struct общедоступный по умолчанию.
template <class KeyType, class ObjectType>
class Vertex
{
KeyType key;
const ObjectType* object;
public:
Vertex(const KeyType& _key, const ObjectType& _object) : key(_key), object(&_object) {}
const KeyType getKey()
{
return key;
}
};
template <class KeyType, class ObjectType>
class Graph
{
map<KeyType, Vertex<KeyType, ObjectType> > vertexes;
public:
const Vertex<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;
}
};
или с typedef:
template <class KeyType, class ObjectType>
class Vertex
{
KeyType key;
const ObjectType* object;
public:
Vertex(const KeyType& _key, const ObjectType& _object) : key(_key), object(&_object) {}
const KeyType getKey()
{
return key;
}
};
template <class KeyType, class ObjectType>
class Graph
{
typedef Vertex<KeyType, ObjectType> tVertex;
map<KeyType, tVertex > vertexes;
public:
const tVertex& createVertex(const KeyType& key, const ObjectType& object)
{
tVertex *vertex = new tVertex(key, object);
vertexes.insert(make_pair(vertex->getKey(), *vertex));
return *vertex;
}
};