Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Implements.cpp
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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(); }
cl.exe
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
edit mode
|
history
|
discussion