You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
664 B
C++
39 lines
664 B
C++
#include <iostream>
|
|
#include "main.h"
|
|
|
|
template<typename T>
|
|
class Wrapper {
|
|
T* impl;
|
|
|
|
public:
|
|
Wrapper(T* obj) : impl(obj) {}
|
|
|
|
T* operator->() { return impl; }
|
|
const T* operator->() const { return impl; }
|
|
|
|
operator T*() { return impl; }
|
|
operator const T*() const { return impl; }
|
|
|
|
operator T&() { return *impl; }
|
|
operator const T&() const { return *impl; }
|
|
};
|
|
|
|
void render_shape_by_ptr(IShape* shape) {
|
|
shape->draw();
|
|
}
|
|
|
|
void render_shape_by_ref(IShape& shape) {
|
|
shape.draw();
|
|
}
|
|
|
|
int main() {
|
|
Circle circle {10};
|
|
Wrapper<IShape> wrapped(&circle);
|
|
|
|
std::cout << wrapped->area() << "\n";
|
|
|
|
render_shape_by_ptr(wrapped);
|
|
|
|
render_shape_by_ref(wrapped);
|
|
}
|