Created
February 14, 2017 01:04
-
-
Save utilForever/dfaf6f4c8154f635841b5967c15c17f3 to your computer and use it in GitHub Desktop.
std::declval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <utility> | |
#include <iostream> | |
struct Default { int foo() const { return 1; } }; | |
struct NonDefault | |
{ | |
NonDefault(const NonDefault&) { } | |
int foo() const { return 1; } | |
}; | |
int main() | |
{ | |
decltype(Default().foo()) n1 = 1; // type of n1 is int | |
// decltype(NonDefault().foo()) n2 = n1; // error: no default constructor | |
decltype(std::declval<NonDefault>().foo()) n2 = n1; // type of n2 is int | |
std::cout << "n1 = " << n1 << '\n' | |
<< "n2 = " << n2 << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment