Register to reply

[C++] Question regarding input data type. Helppp :|

Share this thread:
cikon
#1
Dec18-12, 02:27 AM
P: 2
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 ?
Phys.Org News Partner Science news on Phys.org
World's largest solar boat on Greek prehistoric mission
Google searches hold key to future market crashes
Mineral magic? Common mineral capable of making and breaking bonds
Mark44
#2
Dec18-12, 08:47 AM
Mentor
P: 21,215
Quote Quote by cikon View Post
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 ?
You tell us - it's your code, which by the way won't compile, since q is not declared.
cikon
#3
Dec18-12, 09:45 AM
P: 2
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.

Borek
#4
Dec18-12, 10:50 AM
Admin
Borek's Avatar
P: 23,386
[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.


Register to reply

Related Discussions
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 & Computer Science 7
Struct data input problem.. Programming & Computer Science 6
Matlab- input arguments of type 'double' ? Math & Science Software 2