If there a way to get the type of an object/variable at compile time?

I want to be able to do something like this:

1
2
3
4
Type1 sum(int x, int y){
    setType1(type of x+y);
    return x+y;
}


Is there a way to do this? Thanks
Last edited on
Apparently: http://en.cppreference.com/w/cpp/language/auto


[edit] ... your example is trivial ... int+int returns int ...
Last edited on
you can do it by hand with void* sum approach, but that is sort of a C approach (there are a few places where this is still useful, though). You may also consider a template function. I assume you know you can add atomic types so I assume this is just an example and not your need ... what you do depends a bit on what you need to accomplish.
Topic archived. No new replies allowed.