| New Reply |
[C++] Question regarding input data type. Helppp :| |
Share Thread | Thread Tools |
| Dec18-12, 02:27 AM | #1 |
|
|
[C++] Question regarding input data type. Helppp :|
Helo,
im doing overloading function. example class a { ..... example(int a) ...... example(double b) }; int main() { a. b; cout << "Enter value"; cin>>q; b.example(q) } what is q's data type ? |
| Dec18-12, 08:47 AM | #2 |
|
Mentor
|
|
| Dec18-12, 09:45 AM | #3 |
|
|
im sorry for not making it clear. act i wanna ask, what is the data type of unknown parameter. like q. it can be either int or double. and we do not know what is the type will be inserted by the user.
|
| Dec18-12, 10:50 AM | #4 |
|
Admin
|
[C++] Question regarding input data type. Helppp :|
No, it is not unknown - you have to declare it before using it in main(). Once it is declared and example(q) is called compiler already knows q type and calls the correct overload.
Edit: I think I know what you mean, you have no idea what the user will input beforehand. You have to write code that will analyze the input before storing the information in the variable. q type is not decided during runtime depending on what the user enters, it must be declared earlier. If you need separate example() functions for different input types, you need to call them AFTER checking what was the user input type. |
| New Reply |
| Tags |
| cin, class, overloading function, unknown data input |
| Thread Tools | |
Similar Threads for: [C++] Question regarding input data type. Helppp :|
|
||||
| Thread | Forum | Replies | ||
| Calculate input power from the data | Advanced Physics Homework | 7 | ||
| Is data input clocked? | Engineering, Comp Sci, & Technology Homework | 19 | ||
| how to test input type before storing C++ | Programming & Comp Sci | 7 | ||
| struct data input problem.. | Programming & Comp Sci | 6 | ||
| Matlab- input arguments of type 'double' ???? | Math & Science Software | 2 | ||