现有的答案涵盖了一般情况,但它们有些模糊,我需要确定这一点。
考虑:
然后添加:
我是否需要重新编译链接该库的每个 dll,还是只需要重新编译使用新方法的 dll?
编辑:
我的原始接口(interface)公开了一个动态方法,它是 Dynamic(int OP, void* args) 是否可以添加一个转换为新接口(interface)的操作?
COM 如何设法在不破坏现有接口(interface)的情况下向对象添加新接口(interface)?是否堆叠接口(interface),使用多重继承等???
让我来阐述一下它的工作方式。
静态链接库接口(interface)
In statically linked library
class Interface1
{
virtual Method1() = 0;
virtual Method2() = 0;
}
class NotReallyInterface2 : Interface1
{
virtual Method1() = 0;
virtual Method2() { // does something }
}
在 dll 中
In A.dll
Load statically linked library
class A : NotReallyInterface2
{
virtual Method1() { // does something }
}
In B.dll
Load statically linked library
class B: NotReallyInterface2
{
virtual Method1() { // does something different }
}
我要补充
class Interface3
{
virtual Method3() = 0;
}
我这里有一些问题,因为我的继承结构看起来像。
[a.dll [ library : Interface1 < NotReallyInterface2 ] < A ]
[b.dll [ library : Interface1 < NotReallyInterface2 ] < B ]
所以我很害怕
[ a.dll [ library : Interface1 < NotReallyInterface2 ] < Interface3 < A ]
不会工作。
编辑2
所以我发现了我的问题。显然,其他 dll 和可执行文件正在引用我的 NotReallyInterface2。这意味着多个 dll 和 exe 正在构建相同的基类。因此,如果基类的那些“拷贝”不同步,就会失败。这意味着我无法更改 NotReallyInterface2 中的单个方法签名。
如果没有人引用 NotReallyInterface2,这会奏效,现在我从答案中得到了这一点,整个事情变得有意义了。
最佳答案
您需要重新编译那些直接引用派生类的 DLL。那些只通过接口(interface)引用它的将继续工作。
COM 正是依赖于此。 COM ABI 规范有效地要求每个兼容的 C++ 编译器不要以导致接口(interface)停止工作的方式搞砸 vtable。这就是为什么 COM 的基本要求之一是永远不要通过添加/删除/更改函数或为其提供新的基本接口(interface)来修改已发布的接口(interface)。
通过派生旧接口(interface)并使实现类派生自新接口(interface)来添加新接口(interface)不会破坏它;从实现类中的许多接口(interface)进行多重继承也是如此。
不那么抽象的类不应该成为阻碍,但现在您超出了 COM 的保证范围。如果那个类有数据成员,那就更糟了。我认为不重新编译代码仍然是安全的,但我不想再依赖它了。
关于c++ - 添加新继承的 "interface"和虚拟方法需要重新编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18131122/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它