这个问题与 Stefanus Du Toit 关于沙漏模式的演讲有关。这是一个很棒的演讲,对图书馆作家很有帮助。
Youtube 链接:https ://youtu.be/PVYdHDm0q6Y
幻灯片链接: http ://www.slideshare.net/StefanusDuToit/cpp-con-2014-hourglass-interfaces-for-c-apis
好的,这是问题:
假设我必须通过std::vector<MyObject>
图书馆边界。使用沙漏图案的最佳方法是什么。我关心性能以及保持干净的界面。下面给出了一组我想要实现的示例接口。
客户端 C++ 接口:
void MyLibraryClass::DoSomething(const std::vector<MyObject>& objs);
C接口:
???? (Not sure what is the best practice here)
内部库 C++ 接口:
MyInternalLibraryClass::DoSomething(const std::vector<MyObjectImpl>& objs);
希望这能解释我的问题。