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

  • Thread starter Thread starter cikon
  • Start date Start date
  • Tags Tags
    Data Input Type
AI Thread Summary
The discussion revolves around function overloading in C++ and the issue of determining the data type of a variable based on user input. The original poster presents a code snippet where they attempt to call an overloaded function `example()` with a variable `q`, which is not declared. Respondents clarify that `q` must be declared with a specific data type before it can be used. They emphasize that the type of `q` cannot be dynamically determined at runtime; it must be defined beforehand. To handle varying user inputs, the code should first analyze the input type and then call the appropriate overloaded function based on the determined type. This approach ensures that the correct version of `example()` is invoked according to the user's 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;
cout << "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;
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.
 
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:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Back
Top