Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if defined(_MSC_VER)
- #include <__msvc_all_public_headers.hpp>
- #elif defined(__GNUC__)
- #include <bits/stdc++.h>
- #else
- #error "Unsupported compiler"
- #endif
- using namespace std;
- class Integer {
- public:
- Integer() {
- pval = new int(0);
- cout << "Integer()" << endl;
- }
- Integer(int value) {
- pval = new int(value);
- cout << "Integer(int)" << endl;
- }
- Integer(const Integer& other) {
- pval = new int(*other.pval);
- cout << "Integer(const Integer&)" << endl;
- }
- Integer(Integer&& other) noexcept {
- pval = other.pval;
- other.pval = nullptr;
- cout << "Integer(Integer&&)" << endl;
- }
- int get() const {
- return *pval;
- }
- ~Integer() {
- delete pval;
- cout << "~Integer()" << endl;
- }
- private:
- int* pval = nullptr;
- };
- class Entity {
- public:
- template <typename T1, typename T2>
- Entity(T1&& id, T2&& name) : id(forward<T1>(id)), name(forward<T2>(name)) {
- cout << "Entity(T1&&, T2&&)" << endl;
- }
- template <typename T1, typename T2>
- static Entity* create(T1&& id, T2&& name) {
- return new Entity{ forward<T1>(Integer{ id }), name };
- }
- private:
- Integer id;
- string name;
- };
- int main() {
- Entity e1{ Integer{1}, "Alice" };
- return 0;
- }
Advertisement
Comments
-
- Leon West Accidental Goblin King Audiobooks 1-4
- magnet:?xt=urn:btih:49d386821d7a4093ac6209084242fbdf979b0ac1
- magnet:?xt=urn:btih:9f49b631081256fdab2d7b13927ce27bd44cf683
- magnet:?xt=urn:btih:6ef04c5cd32428d63afbca8a5b754688082059d3
- magnet:?xt=urn:btih:feae4390a335f0743bc8852d70183ace64240e1a
Add Comment
Please, Sign In to add comment
Advertisement