switching variable types in the same code
Posted on 1998-06-09
(Visual C++) if I am writing a database, and I want the user to be able to search based on different fields, is there a way to write the code once with a variable that can change? For example: I'd like then to be able to search for int ID, char name, or int age - all under the same class. I have a statement (in a member function) "if(targetID != searchptr -> ID)..... " I want to be able to use that same statement for the different fields without writing the code 3 different times. Can I set up a variable that can be set to int ID, char name, etc based on what the user wants and just put that variable in my code? This question is from someone learning C++, so answers can't be too vague...