Last active
February 24, 2017 23:32
-
-
Save Bueddl/9f517d92413c17b71a57c6334a830051 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
class IPlugin | |
{ | |
public: | |
virtual void doSth() = 0; // muss implementiert werden | |
virtual void otherToDo() | |
{ | |
std::cout << "default impl called" << std::endl; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "IPlugin.h" // eig nicht nötig | |
#include "MyPlugin.h" | |
#include "MyOtherPlugin.h" | |
#include <vector> | |
#include <memory> // smart pointer | |
int main() | |
{ | |
std::vector<std::shared_ptr<IPlugin>> plugins; | |
plugins.emplace_back(std::make_shared<MyPlugin>()); | |
plugins.emplace_back(std::make_shared<MyOtherPlugin>()); | |
for (auto *plugin : plugins) { | |
plugin->doSth(); | |
plugin->otherToDo(); | |
} | |
// jetzt kümmert sich vector destructor um das aufräumen der shared_ptr und der shared_ptr kümmert sich ums aufräumen der Plugin Objekte | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "IPlugin.h" | |
#include <iostream> | |
class MyOtherPlugin : public IPlugin | |
{ | |
public: | |
void doSth() override | |
{ | |
std::cout << "work work work" << std::endl; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "IPlugin.h" | |
#include <iostream> | |
class MyPlugin : public IPlugin | |
{ | |
public: | |
void doSth() override | |
{ | |
std::cout << "i should so something..." << std::endl; | |
} | |
void otherToDo() override | |
{ | |
std::cout << "I am special" << std::cout; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment