When I compile this:
#ifndef BTREE_H
#define BTREE_H
#include <QList>
template <class T, int degree>
class btree
{
public:
class node
{
public :
node();
private:
node* parent;
QList<T> values;
QList<node*> children;
};
public:
btree();
void insert(const T& value);
node* findLeaf(const T& value);
void performInsertion(const T& value, node& place);
//
node* root;
};
#endif // BTREE_H
Implementation of findLeaf is this:
template <class T, int degree>
btree<T,degree>::node* btree<T,degree>::findLeaf(const T &value)
{
if(root == NULL)
return root;
}
This error occurs:
error: need ‘typename’ before ‘btree<T, degree>::Node’
because ‘btree<T, degree>’ is a dependent scope
The C++ grammar is horrendous, and as such it is not possible, when given a template class, to know whether the
::nodeyou refer to is a variable/constant or a type.The Standard therefore mandates that you use
typenamebefore types to remove this ambiguity, and treats all other usages as if it was a variable.Thus
is the correct signature for the definition.