The definition below is failing… I’m thinking it has something to do with specializing a class template (Vector) within another class template (Graph). Thanks!
this is the part giving me trouble (defined in Graph below) ->
std::map<KeyType, Vertex<KeyType, ObjectType> > vertexes;
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:
std::map<KeyType, Vertex<KeyType, ObjectType> > vertexes;
public:
const Vertex<KeyType, ObjectType>& createVertex(const KeyType& key, const ObjectType& object);
};
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(pair<KeyType, Vertex<KeyType, ObjectType> >(vertex.getKey(), vertex));
return *vertex;
};
Visual Studio 10 reports:
Error 1 error C2228: left of ‘.getKey’ must have class/struct/union c:\documents\visual studio 2010\projects\socialnetwork\socialnetwork\graph.h 46 1 SocialNetwork
The line mentioned in the error corresponds to the the vertexes.insert call near the end.
UPDATE: made correction as suggested by 2 posters of changing the >> to > >. No difference. Error persists.
Your
vertexis a pointer. To accessgetKeyyou need to use->operator, not.. Plus, you can usestd::make_pairto avoid repeating the types.