在这种情况下,可以添加实现存根吗?
我有一个库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
functionFoo
needsY
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 Y
library. Am I correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论