2016-05-08 11 views
0

はありません。これは、コードです:C++エラー:「テンプレートパラメータに依存して 『setw』には引数

template <class TYPE, class KTYPE> 
void AvlTree<TYPE, KTYPE> :: _print (NODE<TYPE> *root, int level) 
{ 
    int i; 

    if (root) 
     { 
     _print (root->right, level + 1); 

     cout << "bal "  << setw(3) << root->bal 
       << ": Level " << setw(3) << level; 

     for (i = 0; i <= level; i++) 
      cout << "...."; 
     cout << setw(3) << root->data.key; 
     if (root->bal == LH) 
      cout << " (LH)\n"; 
     else if (root->bal == RH) 
      cout << " (RH)\n"; 
     else 
      cout << " (EH)\n"; 

     _print (root->left, level + 1); 
     } 

} 

これは、使用してドライバイムです:

AvlTree<node, int> tree; 
if (tree.AVL_Empty()) 
    cout << "tree is empty\n"; 

node newItem; 
newItem.word = "ryan"; 
newItem.key = 1; 
tree.AVL_Insert(newItem); 
tree.AVL_Print(); 

return 0; 

を誤りイム取得することです:

error: there are no arguments to 'setw' that depend on a template parameter, so a declaration of 'setw' must be available [-fpermissive] 

error: 'setw' was not declared in this scope 

私はエラーが消え運と他の同様の質問ごとに「this->」を使用してみましたが、そのreplaています。このエラーが発生しました:

error: 'class AvlTree<node, int>' has no member named 'setw' 
+0

あなたには「」が含まれていますか?これは、['std :: setw'](http://en.cppreference.com/w/cpp/io/manip/setw)が定義されているからです。 – Cornstalks

+0

私の含まれていない:iostream、cstdlibとusing namespace std; – nanjero05

答えて

1

<iomanip>に問題があります。実際にはstd::setwと宣言されているので、そのヘッダファイルをインクルードする必要があります。

コンパイラのエラーは、これでかなり明らかです:'setw' was not declared in this scopesetwが何であるかわからないことを伝えています。 setw<iomanip>ヘッダーに由来するため、コンパイラに正しく通知され、setwが何であるかを知るために、そのヘッダーを含める必要があります。

+0

ありがとうございました – nanjero05

関連する問題