C++ 对象作为接口方法的参数

C++ objects as parameters for interface methods

对于我的 C++ DLL,我使用带有抽象接口的工厂模式。
this article的缺点部分,它说:

An abstract interface method cannot return or accept a regular C++ object as a parameter. It has be either a built-in type (like int, double, char*, etc.) or another abstract interface. It is the same limitation as for COM interfaces.

你能详细说明这是什么意思吗?我不能做什么,为什么?
关于这个问题有任何进一步的阅读吗?

这个说法看起来不准确。抽象接口方法可以 return 或接受 C++ class 实例(或其指针)作为参数。这里没有类似 COM 的限制。尽管 caller/callee 是使用不同的编译器设置、对齐、使用不同的分配器等构建的,但它可能不安全。在这种情况下,相同的 C++ class 的定义略有不同,不匹配可能会导致意外行为。也就是说,它不是关于"cannot",而是关于它可能会导致不明显的问题。

相关问题的一个常见示例是将 CString 作为参数传递:

  • function in dll doesn't receive CString argument value