Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Adaptive return type
#include <iostream> using InnerType = int; struct Any { Any(InnerType val) : m_val{ val } { std::cout << "my ptrs = [" << this << " : " << &m_val << "]\n"; } struct Adaptor { operator InnerType*() const noexcept { return std::addressof(any.m_val); }; operator Any*() const noexcept { return std::addressof(any); }; operator void*() const noexcept { return std::addressof(any); }; Any &any; }; const Adaptor operator&() { return { *this }; } private: bool _filler{}; InnerType m_val{}; }; int main() { Any any{ 123 }; Any *anyPtr = &any; std::cout << "Any ptr = " << anyPtr << "\n"; InnerType *itypePtr = &any; std::cout << "Inner type ptr = " << itypePtr << " : val = " << *itypePtr << "\n"; }
run
|
edit
|
history
|
help
0
ria
C++ quine
infix to postfix v 1.0
Guess a number in c++
MSVC alias template
Dequeue Using STL List
Integral constant
define own struct
Is min defined?
DCapSurfaceDesc