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

  • Context: C/C++ 
  • Thread starter Thread starter cikon
  • Start date Start date
  • Tags Tags
    Data Input Type
Click For Summary

Discussion Overview

The discussion revolves around the data type of a variable in C++ when using function overloading. Participants explore the implications of user input on variable type and the necessity of declaring variables before use in the context of overloaded functions.

Discussion Character

  • Technical explanation, Debate/contested

Main Points Raised

  • One participant asks about the data type of a variable (q) that is intended to be used with overloaded functions, suggesting it could be either int or double based on user input.
  • Another participant emphasizes that the variable must be declared before it can be used, asserting that the compiler determines the type of q at compile time, not at runtime.
  • A later reply clarifies that while the user input type is unknown at the time of declaration, the variable's type must still be defined prior to its use in the function call.
  • There is a suggestion that if different input types are needed, the code should analyze the input before deciding which overloaded function to call.

Areas of Agreement / Disagreement

Participants disagree on the interpretation of variable type determination in relation to user input and function overloading. There is no consensus on how to handle the situation where the input type is uncertain.

Contextual Notes

Limitations include the assumption that the variable must be declared before use, which may not accommodate scenarios where dynamic type determination is desired based on user input.

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 ?
 
Technology 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:

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 25 ·
Replies
25
Views
3K
Replies
12
Views
3K
Replies
2
Views
2K
  • · Replies 39 ·
2
Replies
39
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 35 ·
2
Replies
35
Views
4K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 6 ·
Replies
6
Views
12K