当前位置:网站首页>Hidden implementation and decoupling, knowing Pimpl mode

Hidden implementation and decoupling, knowing Pimpl mode

2022-06-13 04:51:00 Feng jungle

1. PImpl Model introduction

PImpl,Pointer to Implementation, Pointer to implementation . This is a C++ A common pattern in . Strictly speaking, , Limited to pointer form ,PImpl It's not a design pattern , It's just C++ An idiom of a programming language .PImpl Through a private member pointer , Hide the inner implementation of the class pointed to by the pointer . As shown in the figure below :

among , In the header file, you need to PImpl Make a forward statement , And save a private PImpl The pointer . Initialize this pointer in the constructor , Release the pointer in the destructor . Of course , You can also use smart pointers .

In the class A In the implementation of the exposed interface , Than

原网站

版权声明
本文为[Feng jungle]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280519269331.html