consider Following pseudocode...
display(x)
{
if x is of type int
print "integer found"
if x is of type float
print "Float found"
}
main()
{
//few declarations.
display(x);
}
We can achieve this is Python or Ruby easily.
I have problem in C++.
Although, We can use "typeid(variabl e_name).name()" to get the class name.,
We get trapped while declaring the above "display" function as.
display(int or float or somthing_else);
because at the time of declaration we never know, what kind of variable will be.
So, In short How can I achieve this in C++?
Don't say that It can't be done in C++.
Ofcourse this may not be a challenge for some people.
display(x)
{
if x is of type int
print "integer found"
if x is of type float
print "Float found"
}
main()
{
//few declarations.
display(x);
}
We can achieve this is Python or Ruby easily.
I have problem in C++.
Although, We can use "typeid(variabl e_name).name()" to get the class name.,
We get trapped while declaring the above "display" function as.
display(int or float or somthing_else);
because at the time of declaration we never know, what kind of variable will be.
So, In short How can I achieve this in C++?
Don't say that It can't be done in C++.
Ofcourse this may not be a challenge for some people.
Comment