#include <iostream>
#include <type_traits>
class Originator{
typedef int * pStateType;
using rStateType =
typename ::std::remove_pointer< pStateType >::type;
private:
pStateType pState;
public:
Originator( const rStateType& o )
:pState( new rStateType {o} ) {}
Originator( pStateType const p )
:pState( p ) {}
explicit
Originator( const Originator& other )
: pState( new rStateType { *(other.pState)} ) { }
Originator( Originator&& other )
: pState ( &*(other.pState) )
{ other.pState = nullptr; }
public:
class Memento{
private:
Originator::pStateType pState;
public:
Memento( const Originator& O)
:pState( new Originator::rStateType { *(O.pState) } )
{}
public:
Memento( void ) = delete;
explicit Memento( const Originator::pStateType& ) = delete;
Memento( const Memento& ) = default;
Memento( Memento&& other )
: pState( &*(other.pState) )
{ puts("Memento::&& con
【设计模式:memento pattern】
于 2024-02-02 17:58:52 首次发布