【发布时间】:2011-04-02 20:46:16
【问题描述】:
下面的定义失败了......我认为它与在另一个类模板(Graph)中专门化一个类模板(Vector)有关。谢谢!
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 报告:
错误 1 错误 C2228:'.getKey' 左侧必须有类/结构/联合 c:\documents\visual studio 2010\projects\socialnetwork\socialnetwork\graph.h 46 1 SocialNetwork
错误中提到的行对应于接近末尾的 vertexes.insert 调用。
更新:按照 2 个将 >> 更改为 >> 的海报的建议进行了更正。没有不同。错误仍然存在。
【问题讨论】:
-
您将不得不分享错误消息。
-
失败是怎么回事?您使用哪种编译器?