I have defined this function in my header of the class ContextFreeGrammar:
friend ContextFreeGrammar & operator<<(ContextFreeGrammar & cfg, string toRead);
and it is implemented in the cpp file as :
ContextFreeGrammar & operator<<(ContextFreeGrammar & cfg, string toRead)
{
  if (toRead[0] == 'I')
  {
    string parsedNameOfVariable = Variable::parseLabel(toRead.substr(1, toRead.length() - 1));
    cfg.setInitialVariable(Variable(parsedNameOfVariable));
    return cfg;
}
  Rule newRule = Rule::parseLabel(toRead);
  cfg.addRule(newRule);
  return cfg;
}
however in the main() when I create this object and initalize it (ContextFreeGrammar.h is imported) :
    ContextFreeGrammar cfg;
        cfg << "{A}->{B}"
            << "{B}->{C}"
            << "{C}->{D}"
            << "{D}->a{N}"
            << "{B}->c";
I get this error :|undefined reference to `operator<<(ContextFreeGrammar&, std::__cxx11::basic_string, std::allocator >)'|
