Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!rpi!crdgw1!montnaro From: montnaro@spyder.crd.ge.com (Skip Montanaro) Newsgroups: comp.lang.c++ Subject: different member functions with same arg types? Message-ID: Date: 19 Jan 91 04:07:44 GMT Sender: news@crdgw1.crd.ge.com Reply-To: montanaro@crdgw1.ge.com (Skip Montanaro) Organization: GE Corporate Research & Development, Schenectady, NY Lines: 50 I am writing a parser class for a small language. I'd like it to be able to parse input from strings and files. The natural class interface (for me) is something like: class parser : public ... { ... public: parse(char *string); parse(char *filename); ... } Unfortunately, both strings and filenames are char *'s, so the compiler can't distinguish the two interfaces. Is it kosher to add a dummy argument to one member function? It seems crude to me: class parser : public ... { ... public: parse(char *string); parse(char *filename, unsigned int dummy); ... } The other idea that occurs to me is to use a class to contain either the string or the filename, but not both: class parser : public ... { ... public: parse(String string); parse(char *filename); ... } This seems like overkill, when all I want is the string's value, not all the other baggage of the String class. I'm open to suggestions for alternate interfaces. (BTW, I'm a C++ novice.) Thx, -- Skip (montanaro@crdgw1.ge.com)