Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
auto Keyword Example
#include <iostream> #include <cmath> #include <typeinfo> template<class T, class U> auto add(T t, U u) -> decltype(t + u) // the return type is the type of operator+(T, U) { return t + u; } int main() { bool t = true; auto a = 1 + (int)t; std::cout << "type of a: " << typeid(a).name() << '\n'; auto b = 1.2 + 2.3; std::cout << "type of b: " << typeid(b).name() << '\n'; auto c = add(1, 1.2); std::cout << "type of c: " << typeid(c).name() << '\n'; auto d = true; std::cout << "type of d: " << typeid(d).name() << '\n'; float e = 1.2; auto f = e + (float)1.1; std::cout << "type of f: " << typeid(f).name() << '\n'; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
MY FIRST OBJECT ORIENTED PROGRAM
INHERIT_CTORS default constructor
Recursive Call Example Sum
1337
why
ternary test c++14
Atomic trivial default constructor
Access namespace by unqualified manner
10226
template specialization inheritance solution
Please log in to post a comment.