-2

Hi I am new to oops in cpp. I define a class for trie Node as follows. But I get this error and I couldnot find where I am wrong. Thanks in advance.

Error : Line 5: expected identifier before numeric constant

class Node {
        public:
            bool end;
            char val;
            vector<Node *> children(26);
        Node(char val)
        {
            val=val;
            end=false;
            for(i=0;i<children.size();i++)
                children[i]=NULL;
        }
};
danish sodhi
  • 1,793
  • 4
  • 21
  • 31
  • 1
    Either use `vector children{26};` or `vector children = vector(26);`, or use member init list, as user0042 suggests. – HolyBlackCat Sep 10 '17 at 16:50

1 Answers1

3

Should be

     vector<Node *> children;
Node(char val) : end(false), val('\0'), children(26)
{
    // ...

Use the member initializer list to call specific member variable constructors.

user0042
  • 7,917
  • 3
  • 24
  • 39