我有一個類型模板類的向量,我試圖打印它,但得到一個奇怪的錯誤。在控制檯上打印矢量
這裏是我的類:
template <typename VertexType, typename EdgeType> class Vertex{
private:
typedef std::vector<std::pair<int, EdgeType> > VertexList;
std::vector<Vertex<VertexType, EdgeType>> Vertice;
public:
void Add(Vertex);
};
添加方法和打印聲明:
template <typename VertexType, typename EdgeType> void Vertex<VertexType, EdgeType> ::Add(Vertex v)
{
int count = 5;
//std::vector<string>temp;
for(int i=0; i<count; i++)
Vertice.push_back(v);
for(int i=0; i<Vertice.size(); i++)
cout<< Vertice[i] <<endl;
}
main()方法:
int main()
{
Vertex<std::string, std::string> v1;
v1.Add(v1);
std::getchar();
}
錯誤我得到的是:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'Vertex' (or there is no acceptable conversion)
錯 - >'typedef std :: vector VerticeList; .... ....你認爲'typename'是一個類型? –
Nawaz
2011-04-09 15:54:40
哦,我不使用那個矢量,因爲它現在是任何地方......我會評論這一點。 – 2011-04-09 15:55:20
你沒有評論。 – Nawaz 2011-04-09 15:56:00