Name: Anonymous 2013-12-20 16:52
I'm learning to program. All of my programs for my assignments are console applications. Sometimes things get fancy with fstream and text files, but I'm doing beginner work.
A lot of my programs ask for user input. Since they're console applications, it's console input. I always have to write a while loop that checks for invalid input and loops until the input is valid. What a pain!
So I want to write an input class. The class will have virtual functions and use templates. I want to have the function work like this:
InputVal inv; //declaration of instance of InputVal class object "inv"
inv(variable); //variable can be a double or int. later i will add char support to the class. takes variable by reference and a virtual function is chosen based on the variable's type
The virtual function would be so I can have the class appropriately choose its function based on the type of variable passed as a parameter. A template would be so I don't have to write the same function twice for short, double, int, long int, etc. I wonder if I need to use a virtual function AND a template or if I can just use a template...
:)
A lot of my programs ask for user input. Since they're console applications, it's console input. I always have to write a while loop that checks for invalid input and loops until the input is valid. What a pain!
So I want to write an input class. The class will have virtual functions and use templates. I want to have the function work like this:
InputVal inv; //declaration of instance of InputVal class object "inv"
inv(variable); //variable can be a double or int. later i will add char support to the class. takes variable by reference and a virtual function is chosen based on the variable's type
The virtual function would be so I can have the class appropriately choose its function based on the type of variable passed as a parameter. A template would be so I don't have to write the same function twice for short, double, int, long int, etc. I wonder if I need to use a virtual function AND a template or if I can just use a template...
:)