sr think sr think - 1 month ago 10
C++ Question

expected class-name before '{' token error

I'm getting the error "expected class-name before '{' token" in my C++. I am trying to inherit the avlTree class into the word search class, but it is not working.

#ifndef WORDSEAR_H
#define WORDSEAR_H

#include <string>
#include "avlTree.h"

class wordSearch: public avlTree
{ <----error right here
public:
//functions are here
private:
};

#endif


this is avlTree.h

#ifndef AVLTREE_H
#define AVLTREE_H

template <class myType>
struct nodeType {
myType keyValue;
nodeType<myType> *left;
nodeType<myType> *right;
};

template <class myType>
class avlTree
{
public:
//functions are here
private:
};
#endif

Answer

avlTree is a class template, you need to specify the template argument for it:

class wordSearch: public avlTree<something>

According to your intent, you might make wordSearch class template too:

template <typename myType>
class wordSearch: public avlTree<myType>
Comments