Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Implements.cpp
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #include <iostream> #include <string> #include <vector> #include <memory> #include <type_traits> #include <functional> struct query_interface { template <class T> static decltype(std::declval<T>().queryInterface()) execute(T* pImpl_) { std::cout << "query_interface\n"; return pImpl_->queryInterface(); } }; template<class T> class interface { public: inline void * query_interface() { std::cout << "interface\n"; return query_interface::execute(pImpl_); } interface(T * smth) : pImpl_(smth) { } private: T * pImpl_; }; class Itest { }; class Itest2 { }; class Itest3 { }; template<typename T, typename... Args> class Implements : public T, public virtual Implements<Args...> { public: inline void * queryInterface() { std::cout << "implements all " << typeid(T).name() << "\n"; return Implements<Args...>::queryInterface(); } }; template<typename T> class Implements<T> : public T { public: inline void * queryInterface() { std::cout << "implements base " << typeid(T).name() << '\n'; return nullptr; } }; class test : public Implements<Itest,Itest2,Itest3> { public: }; int main() { test t; interface<test> i(&t); i.query_interface(); }
run
|
edit
|
history
|
help
0
Computing the factorial of an integer using factorial and iteration
Calculate sum between two numbers using for-, while-, and do-while loops
c++
Regex pipe and tabs c++
Why is vsnprintf Not Writing the Same Number of Characters as strncpy Would?
Adaptive return type
cv5
du
why fatal error C1083
Computing factorial of an integer with recursion and iteration