2009-08-29 3 views
1

ながら:エラー私は、次のCPPコードスニペットと、関連するエラーメッセージを持つベクトルへのポインタを挿入

コードは

struct node{ 
      char charVal; 
      bool childNode; 
      struct node *leftChild; 
      struct node *rightChild; 
    }; 
    vector<std::pair<int,struct node*> > nodeCountList; 
    struct node *nodePtr = new struct node; 
    nodeCountList.push_back(1,nodePtr); 

エラーメッセージ

error: no matching function for call to ‘std::vector<std::pair<int, node*>, std::allocator<std::pair<int, node*> > >::push_back(int&, node*&)’ 
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_vector.h:602: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = std::pair<int, node*>, _Alloc = std::allocator<std::pair<int, node*> >] 

をしてくださいスニペットエラーメッセージのトラブルシューティングを手伝ってください。

歓声

答えて

7

std :: pairをプッシュする必要があります。

nodeCountList.push_back(std::make_pair(1,nodePtr)); 
1

あなたが最初の型に「ノード」をturining、その後、テンプレートを使用してみましたか?多分、これはうまくいくでしょう。

2

nodeCountList.push_backに2つの引数を渡そうとしていますが、1つの引数しか受け付けません。代わりに、最初にstd::pairを作成し、そこに2つのアイテムを入れます。次に、std::pairを引数としてnodeCountList.push_backを呼び出します。

関連する問題