Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
IceCream
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
//g++ 7.4.0 #include <iostream> #include <vector> #include <string> class IIceCream { public: virtual std::string print() = 0; }; template<typename T> class IceCream final : public IIceCream { public: IceCream(T your_choice) { mChoosen = your_choice; } std::string print() final { return std::to_string(static_cast<typename std::underlying_type<T>::type>(mChoosen)); } friend std::ostream& operator<< (std::ostream& out, const IceCream<T>& day); private: T mChoosen; }; enum class My_creams { CORNETTO, SANDWHICH, TIPTOP, }; template <typename T> std::ostream& operator<< (std::ostream& out, const IceCream<T>& day) { std::cout << "test"; } int main() { auto my_best = My_creams::TIPTOP; auto my_best_ice_cream = new IceCream<My_creams>(my_best); auto my_selection = std::vector<IIceCream *>(); my_selection.push_back(my_best_ice_cream); for (auto aCream : my_selection) { std::cout << aCream->print(); } }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.53 sec, absolute running time: 0.17 sec, cpu time: 0.01 sec, memory peak: 3 Mb, absolute service time: 0,87 sec
edit mode
|
history
|
discussion
2