online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
//Für eine Art Komponenten-Konzept ala COM (+ abstrakte Schnittstellen über DLL Grenzen mit anderen CRTs) //Um meine Architektur noch "benutzungssicherer" zu machen versuche ich gerade: //1. zu verhindern das meine Klassen direkt auf dem Stack oder Heap erzeugbar sind //2. zur Kompilierzeit zu prüfen ob die Klasse auch diesen Anforderungen entspricht //3. einen Weg zu finden wie das "Konzept" z.B. über Ableitung leichter auf viele Klassen angwendet werden kann #include <type_traits> #include <memory> #include <iostream> class ConstructorKey { friend class Factory; private: constexpr ConstructorKey() noexcept {}; constexpr ConstructorKey(ConstructorKey const&) noexcept = default; }; class OnlyFactoryConstructible { protected: constexpr OnlyFactoryConstructible(const ConstructorKey &) noexcept { } }; class ClassA : OnlyFactoryConstructible { public: ClassA(const ConstructorKey &key) : OnlyFactoryConstructible(key) { } ClassA(const ConstructorKey &key, int a) : ClassA(key) {} ClassA(const ConstructorKey &key, int a, float b) : ClassA(key) {} void helloWorld() { std::cout << "Hello World" << std::endl; } }; class Factory { public: template <class T, typename... ARGS> static std::unique_ptr<T> get(ARGS&&... args) { return std::make_unique<T>(ConstructorKey(), std::forward<ARGS>(args)...); } }; int main() { // Compiliert und funktioniert: std::unique_ptr<ClassA> ptr = Factory::get<ClassA>(1,2.0); ptr->helloWorld(); // compiliert nicht: // ClassA a(1, 2.0); // ClassA a(ConstructorKey(), 1, 2.0); // ClassA *a = new ClassA(1,2.0); // ClassA *a = new ClassA(ConstructorKey, 1, 2.0); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue