Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- template <typename T>
- class IObserver {
- public:
- virtual void Next(const T& value) noexcept = 0;
- };
- template <typename T1, typename T2>
- class BinaryObserver : public IObserver<T1>, public IObserver<T2> {
- public:
- void Next(const T1& value) noexcept override{};
- void Next(const T2& value) noexcept override{};
- };
- int main() {
- // This is OK
- BinaryObserver<int, float> mc1;
- mc1.Next(0);
- mc1.Next(0.0f);
- // This fails to compile with "multiple overloads"
- BinaryObserver<int, int> mc2;
- mc2.Next(0);
- mc2.Next(0);
- }
- template <typename T>
- class BinaryObserver<T, T> : public IObserver<T> {
- public:
- void Next(const T & value) noexcept override{};
- };
- BinaryObserver<int, int> mc2;
- mc2.Next(0);
- mc2.Next(0);
- class BinaryObserver : public IObserver<T1>, public IObserver1<T2>
- ...
- mc2.Next(0);
- mc2.Next1(0);
- template <typename T1, typename T2>
- class BinaryObserver : public IObserver<T1>, public IObserver<Shell<T2>> {
- public:
- void Next(const T1& value) noexcept override{T1 t = value;};
- void Next(const Shell<T2>& value) noexcept override{T2 t = value;};
- };
- ...
- BinaryObserver<int, float> mc1;
- mc1.Next(0);
- mc1.Next(0.0f);
- BinaryObserver<int, int> mc2;
- mc2.Next(0);
- mc2.Next(Shell<int>(0));
Add Comment
Please, Sign In to add comment