C++ (Qt)class ISomeClass{ ... template <class T> virtual void doSomething(T value) = 0;}
C++ (Qt)#include <ISomeClass.h> class SomeConcreteClass : public ISomeClass{ ... template <class T> void doSomething(T value) override { std::cout << "SomeConcreteClass value = " << value << std::endl; }}
C++ (Qt)#include <ISomeClass.h> ISomeClass * makeSomeObject();
C++ (Qt)#include <SomeConcreteClass.h>ISomeClass * makeSomeObject(){ return new SomeConcreteClass();}
C++ (Qt)ISomeClass * some_object = makeSomeObject();some_object->doSomething(int(10));some_object->doSomething(double(5.7));
C++ (Qt)ISomeClass * some_object = makeSomeObject();
C++ (Qt)QWidget * widget = new QWidget();some_object->doSomething(widget);
class ISomeClass{ template <class T> virtual void doSomething(T value) = 0;}
C++ (Qt)#include <ISomeClass.h>class SomeConcreteClass : public ISomeClass{ template <class T> void doSomething(T value) override { std::cout << "SomeConcreteClass value = " << value << std::endl; }}
class ISomeClass{ virtual void doSomething(int value) = 0; virtual void doSomething(double value) = 0;}class SomeConcreteClass : public ISomeClass{ void doSomething(int value) override { std::cout << "SomeConcreteClass value = " << value << std::endl; } void doSomething(double value) override { std::cout << "SomeConcreteClass value = " << value << std::endl; }}
some_object->doSomething(new QWidget());
class ISomeClass{ virtual void doSomething(int value) = 0; virtual void doSomething(double value) = 0; virtual void doSomething(QWidget* value) = 0;}
#include <iostream>struct base{ virtual void doSomething(int value) = 0; base* sample = nullptr; // <--- regular in real code};struct concrete: base{ ~concrete() { sample->doSomething(10); // <--- upps } };struct der: concrete{ der() { this->sample = this; // bomb } virtual void doSomething(int value) { std::cout <<"doSomething("<<value<<")\n"; }};int main(){ der d; //<--- babah!!!}