M
Marcin Vorbrodt
Taken out of C++ In a Nutshell book...
Example 7-18: Using an abstract classes as interface specification.
struct Runnable {
virtual void run() = 0;
};
struct Hashable {
virtual size_t hash() = 0;
};
class Thread : public Runnable, public Hashable {
public:
Thread() { start_thread(*this); }
Thread(const Runnable& thread) { start_thread(thread); }
virtual void run();
virtual size_t hash() const { return thread_id(); }
size_t thread_id() const;
...
private:
static void start_thread(const Runnable&);
};
What would the advantage be of using struct as an interface (pure virtual
base class)?
Thanks,Martin
Example 7-18: Using an abstract classes as interface specification.
struct Runnable {
virtual void run() = 0;
};
struct Hashable {
virtual size_t hash() = 0;
};
class Thread : public Runnable, public Hashable {
public:
Thread() { start_thread(*this); }
Thread(const Runnable& thread) { start_thread(thread); }
virtual void run();
virtual size_t hash() const { return thread_id(); }
size_t thread_id() const;
...
private:
static void start_thread(const Runnable&);
};
What would the advantage be of using struct as an interface (pure virtual
base class)?
Thanks,Martin