这是代码:

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->”作为其他类似的问题,但是没有运气。错误消失了,但被以下错误代替:

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

最佳答案

问题是您不包含<iomanip>。您需要包括该头文件,因为这实际上是声明std::setw的内容。

请注意,编译器错误在以下内容上非常清楚:'setw' was not declared in this scope。它告诉您它不知道setw是什么。由于setw来自<iomanip>头,因此您需要包括该头,以便正确告知编译器并知道setw是什么。

关于c++ - C++错误:“没有'setw'参数依赖模板参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37096246/

10-10 03:19