Hello,
I'm currently working on a project that basically reads some text and then performs basic Lexical Analysis on the text. I'm having a slight problem
with overloading methods.
So for example, I have a method that can read in the words from a txt file and another method which reads takes the text just from a string, but, I'm using the same method name, and, the same variable type so obviously it cannot be overloaded. For example:
#ifndef _readWords_h
#define _readWords_h
#include <iostream>
#include <vector>
using namespace std;
class Lexical
{
public:
Lexical();
Lexical(string theFileName);
vector<string> Parser(string fileName);
vector<string> Parser(string theWords);
protected:
vector<string> words;
string fileName;
};
#endif
The method Parser cannot be overloaded. Now is there a way that I could overload this method OR should I have two more classes that inherit from this class and have Parser as a virtual function and call the correct class? E.g. readFromTXT, readFromString both inheriting from Lexical.
Any help would be greatly appriciated :)