0
template<class V, class E>
class G
{
public:
G();
void InsertVertex(const V&);
void InsertEdge(const V&, const V&, const E&);
private:
typedef set<V,less<V> > vSet;
typedef pair<const V,V> ePair;
typedef multimap<V,V,less<V> > eSet;
typedef map<ePair,E, less<ePair> > edgeValueMap;
vSet vertices;
eSet edges;
edgeValueMap edgeVals;
};
template<class V,class E>
G<V,E>::G(){}
template<class V,class E>
void G<V,E>::InsertVertex(const V& a)
{
vertices.insert(a);
}
template<class V,class E>
void G<V,E>::InsertEdge(const V& a,const V& b, const E& val)
{
//create a pair
ePair<const V,v> e(a,b);
edges.insert(e);
edgeVals.insert(e,val);
}
int main()
{
G<char,int> g;
g.InsertVertex('a');
g.InsertVertex('b');
g.InsertVertex('c');
g.InsertEdge('a','b',1);
return 0;
}
而我创建使用 “ePair E(A,B)” 我收到错误的一对: “template2.cpp:39:2:错误: 'G :: ePair' 不是模板” 我我不确定为什么这个编译错误即将到来?我错过了什么吗?如何在C++中初始化这个模板对?
ePair是一个std ::对'与已模板参数typedef''d。 – 2012-02-08 10:54:16
请显示'ePair'的声明。 – 2012-02-08 11:29:29