摘要:
class A{public: // Interface. void foo() { cout foo(); m_b->bar(); m_c->baz(); }};int main(int argc, char *argv[]){ Facade f(new A, new B, new C); f.qux(); // TODO: Release memory. return 0;} 阅读全文
摘要:
qingwenclass Component{public: virtual void foo() = 0;};class LeafA : public Component{public: // Interface. virtual void foo() override { cout m_components;public: // Interface. virtual void foo() override { for (auto i : m_components) { i->foo(); } } void add(Component *componen... 阅读全文
摘要:
class Adaptee{public: // Interface. void operator()(int a, int b, int c) { cout <<a; }};class Target{public: // Interface. virtual void operator()(int a) = 0;};class Adapter : public Target{ // data. Adaptee m_adaptee;public: Adapter(Adaptee &adaptee) : m_adaptee(adaptee) {}publ... 阅读全文
摘要:
// Singleton.hclass Singleton{private: Singleton() {} ~Singleton() {} Singleton(Singleton const &other); Singleton &operator=(Singleton const &other);public: static Singleton &Instance() { return ms_singleton; } static Singleton ms_singleton;};// Singleton.cpp// PUT IT in ".cpp& 阅读全文
摘要:
class Prototype{public: virtual Prototype *Clone() = 0;};class PrototypeA : public Prototype{public: virtual Prototype *Clone() override { return new PrototypeA(*this); }};class PrototypeB : public Prototype{public: virtual Prototype *Clone() override { return new Pro... 阅读全文
摘要:
static constunsigned *s_someNames[aConstexpr];storage _ cv-qualification _type+ operator _ declarator-id _ operator;declarationdeclarator;put 'const' specifier to right of declaration is goes from here:http://www.dansaks.com/articles/1999-02%20const%20T%20vs%20T%20const.pdfI thouht 'cons 阅读全文
摘要:
class T{ int *m_p; void foo() const { *m_p = 1234; }}; 不谈 'm_p' 的初始化及资源释放问题. 在 const member function 中, 竟然能修改类的成员变量? 这并不奇怪, 因为 const 成员函数的实质是: 不改变类的成员变量的值. 由于 'm_p' 是一个指针, 所以 const 的保护作用只能做用于不修改这个指针的值, 而不能限制指针所指向的内存的值.reference: http://bbs.csdn.net/topics/40265282 阅读全文
摘要:
/* * ProductA. */class ProductA {};class Product1_A : public ProductA {public: Product1_A() { cout CreateProductA(); ProductB *pB = f->CreateProductB(); // TODO: Release memory. return 0;} 适用于类成分相同, 但是属于不同的系统。例如:windows 和 linux 的窗口应用程序组件。 此模式就像笛卡尔积一样, 使用一个抽象的工厂, 交叉的创建了某一系列的所有组件. 阅读全文
摘要:
class Product {};class ProductA : public Product{public: ProductA() { cout <<"ProductA" <<endl; }};class ProductB : public Product{public: ProductB() { cout <<"ProductB" <<endl; }};class Creator{public: virtual Product *anOperation() = 0; virtual Product * 阅读全文
摘要:
class Builder{protected: // data. string m_res;public: // Interface. virtual void buildPartA() = 0; virtual void buildPartB() = 0; virtual void buildPartC() = 0; string getRes() { return m_res; }};class BuilderA : public Builder{public: virtual void buildPartA() override { m_... 阅读全文
摘要:
// main.cc//#include #include using namespace std;static int s_id = 0;class Observer;class Subject{ // data. vector m_observers;public: virtual ~Subject();public: // Interface. void addObserver(Observer *observer); void updateObservers();};class Observer{ // data. Subject *m_... 阅读全文
摘要:
#include #include using namespace std;class Visitor;class Element{public: virtual void accept(Visitor &vistor) = 0;};class Visitor{public: virtual void VisitElementA() = 0; virtual void VisitElementB() = 0;};class VisitorA : public Visitor{public: virtual void VisitElementA() { cout m_e... 阅读全文
摘要:
总体来看, c++11 从 5 方面进行了改善:语言更加严谨:(nullptr, enumClass, initializerList, override)语法更加便利:(auto, R"()", lambda, non static const member variable initialization)更大灵活性:(userDefinedLiterals)更加强大的底层控制:(alignas, alignof)更强大的库:(regex, 异步, 线程)autoThe use ofautoto deduce the type of a variable from its 阅读全文