Inspired with real D language feature: http://wiki.dlang.org/Voldemort_types
Compile in GCC/Clang with -std=c++14
.
#include <iostream>
#include <typeinfo>
auto eh() {
struct Voldemort {
int b;
};
return Voldemort{3};
}
int main() {
//eh()::Voldemort c = eh(); // no, error
//eh::Voldemort c = eh(); // nope
//Voldemort c = eh(); // also nope
auto c = eh(); // works!
// demangled type says eh()::Voldemort but cannot be used
std::cout << "type: " << typeid(c).name() << std::endl;
std::cout << "value: " << c.b << std::endl;
}