在这种情况下,可以添加实现存根吗?

发布于 2025-02-04 21:39:05 字数 915 浏览 2 评论 0原文

我有一个库x,我在C ++中的另一个库(例如y)周围添加包装器。

在所有源文件中,每次我使用y功能添加实现时,我都会使用名为x_with_y_wrappers的标识符进行守护所有内容。现在,考虑一个源文件,我在其中实现了一个函数foo

#ifdef X_WITH_Y_WRAPPERS
void Foo(const Xtype& arg1, const Xtype& arg2, Ytype& arg3){
//implementation
}
#endif

在此处使用xtype我的意思是,该变量的类型是我的原始库x的一种类型,而ytype是与其他库有关的类型。

到目前为止,一切都很好。现在,一个开发人员问:

“添加默认实现,该实现会引发错误 函数foo需要y要安装。”

foo 需要

#ifdef X_WITH_Y_WRAPPERS
void Foo(const Xtype& arg1, const Xtype& arg2, Ytype& arg3)  
//implementation using library `Y` inside
}
#else
void Foo(const Xtype& arg1, const Xtype& arg2, Ytype& arg3)
//assert
}
#endif

函数代码>需要安装库以作为参数传递,对吗? 库。

I have a library X, and I'm adding wrappers around another library, say Y, in C++.

In all the source files, every time I add implementations using Y functionalities, I guard everything with an identifier called X_WITH_Y_WRAPPERS. Now, consider a source file where I have implemented a function Foo :

#ifdef X_WITH_Y_WRAPPERS
void Foo(const Xtype& arg1, const Xtype& arg2, Ytype& arg3){
//implementation
}
#endif

here with Xtype I mean that the type of the variable is a type of my original library X, while Ytype is a type related to the other library.

So far so good. Now, a developer asked:

"Add a default implementation which throws an error saying the
function Foo needs Y to be installed."

I'd do the following:

#ifdef X_WITH_Y_WRAPPERS
void Foo(const Xtype& arg1, const Xtype& arg2, Ytype& arg3)  
//implementation using library `Y` inside
}
#else
void Foo(const Xtype& arg1, const Xtype& arg2, Ytype& arg3)
//assert
}
#endif

but I don't understand how this can make sense, as Ytype arg3 needs the library Y to be installed in order to be passed as an argument, right? I think the requested change would make sense only if the third input argument doesn't depend on Ylibrary. Am I correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文