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

  • Context: C/C++ 
  • Thread starter Thread starter cikon
  • Start date Start date
  • Tags Tags
    Data Input Type
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 2K views
cikon
Messages
2
Reaction score
0
Helo,

im doing overloading function.

example
class a
{
... example(int a)
... example(double b)
};

int main()
{
a. b;
count << "Enter value";
cin>>q;
b.example(q)

}

what is q's data type ?
 
Physics news on Phys.org
cikon said:
Helo,

im doing overloading function.

example
class a
{
... example(int a)
... example(double b)
};

int main()
{
a. b;
count << "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.
 
im sorry for not making it clear. act i want to 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.
 
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.
 
Last edited: