pimpl-idiom

    0热度

    2回答

    试想一个典型PIMPL方法的实现: class ObjectImpl; class Object { Object(ObjectImpl* object_impl) : _impl(object_impl); private: ObjectImpl* _impl; }; 我正在寻找一种方法可以重复使用相同的实现包装类型T这两种的ObjectImpl或

    0热度

    1回答

    我在使用cereal时遇到了PIMPL惯用语的麻烦。 这是一个小例子: b.h #ifndef _B_H_ #define _B_H_ #include <memory> #include "cereal/types/memory.hpp" #include "cereal/archives/json.hpp" struct BImpl; class B { public:

    3热度

    2回答

    我有一些的3rdParty库这样的方法: bool Invoke(const char* method, Value* args, size_t nargs) 它需要其内类型的数组(可转换至任何原语C++类型)和Arg计数作为其内PARAMS。 在我的代码,我写了一些通用的辅助,以避免每个调用手动创建和类型的皈依: template<class ... Args> bool WrappedV

    2热度

    1回答

    我的一个队友经常使用的PIMPL的变化,他确实是这样的: 了foo.h: namespace { struct Impl; } class Foo { public: Foo(); ~Foo(); void Bar(int n); /* ... */ private: std::unique_ptr<Impl> _impl; };

    -1热度

    1回答

    我想了解一个来自“api设计为c + +”书(p。70)的疙瘩示例。 // autotimer.h class AutoTimer { public: explicit AutoTimer(const std::string &name); AutoTimer(); // allow access from other classes/functions in

    2热度

    2回答

    我读这个答案霍华德Hinnant(Is std::unique_ptr<T> required to know the full definition of T?),然后这个答案(How is a template instantiated?),我只是在想。如果你有像这样 class Something { Something(); ~Something(); cla

    4热度

    1回答

    我正在阅读Scott Meyers的Effective Modern C++,他在讨论使用pimpl成语并指向unique_ptr的实现类,但存在特殊成员函数的问题(例如作为析构函数)要求类型完整。这是因为unique_ptr的默认删除程序在使用delete p之前会静态声明要删除的类型是否已完成。因此,必须在实现文件中定义该类的任何特殊成员函数(而不是由编译器生成),之后的实现类已定义。 在本章

    0热度

    1回答

    只要我不将构造函数的定义(B)移动到标头B.h,代码就会工作。 B.h class Imp; //<--- error here class B{ public: std::unique_ptr<Imp> imp; B(); //<--- move definition to here will compile error ~B(); ////

    1热度

    2回答

    这是简化代码只是为了显示我的问题: 的main.cpp #include "one.hpp" #include <iostream> int main(){ One one; std::cout << one.two->val; } one.hpp: struct Two; <- forward declare Two struct One{ One(); ~One() {

    0热度

    1回答

    我尽量让PIMPL模式: //header #include <memory> class Table { public: Table(); private: class Impl; std::unique_ptr<Impl> *m_impl; }; //source #include <vector> #include "table.hpp"