简体   繁体   English

使用范围解析运算符时的语法错误

[英]Syntax Errors when using Scope Resolution Operator

I keep getting a syntax error 我一直收到语法错误

"error: expected ';' before "a""

on the line AVL_Tree<val_type>::node_type a; 在线AVL_Tree<val_type>::node_type a; using the Cygwin gcc compiler under Netbeans. 在Netbeans下使用Cygwin gcc编译器。

in class "MyMap.h" 在“MyMap.h”类中

#include "AVL_Tree.h"
template <class key_type,class mapped_type>
class MyMap
{
public:
    class iterator
    {
        private:
            AVL_Tree<val_type>::node_type a;
    };
};

in file "AVL_Tree.h" 在文件“AVL_Tree.h”中

 template <class T>

 class AVL_Tree
 {
 public:
    struct AVLNode
    {
        int balanceFactor;
        T element;
        AVLNode * left;
        AVLNode * right;

        AVLNode(T key)
        {
            left = 0;
            right = 0;
            element = key;
            balanceFactor = 0;
        }
       typedef AVLNode * node_type;
    };

I was under the impression that I was able to access the "node_type" using the scope operator because the typedef in AVL_Tree is public. 我的印象是我能够使用范围运算符访问“node_type”,因为AVL_Tree中的typedef是公共的。 The syntax error isn't being very helpful in telling what exactly is going on. 语法错误对于确定究竟发生了什么并不是很有帮助。 Any help is greatly aprreciated. 任何帮助都会受到极大的重视。

You need to use typename because node_type is a dependent type. 您需要使用typename因为node_type是依赖类型。 Also, node_type is inside AVLNode : 另外, node_typeAVLNode

typename AVL_Tree<val_type>::AVLNode::node_type a;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM