I keep getting a syntax error
"error: expected ';' before "a""
on the line AVL_Tree<val_type>::node_type a;
using the Cygwin gcc compiler under Netbeans.
in class "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"
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. 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. Also, node_type
is inside AVLNode
:
typename AVL_Tree<val_type>::AVLNode::node_type a;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.