If we have the following simple code in C#:
class Program
{
static void Main(string[] args)
{
string x = "Hello World";
test(x);
int y = 101;
test(y);
Console.ReadKey();
}
static void test(object val)
{
Console.WriteLine(val);
}
}
So, we have a reference type object as parameter – works fine. How to do a similar thing in C++?
OT: Without direct typing we can use var keyword, in C++ exists keyword auto. Is here any similar reference type like object or some way/tricks to prove it?
In C++, not all objects derive from a common base type; there is no universal run-time polymorphism. You might get the behavior you need, however, by using compile-time polymorphism via templates.