首页 \ 问答 \ 我可以在基类中重载纯虚函数吗?(Can I overload pure virtual method in the base class?)

我可以在基类中重载纯虚函数吗?(Can I overload pure virtual method in the base class?)

在下面的例子中,我有一个纯虚拟方法(又名FUN1)和一个普通方法(又名FUN2)的抽象类。

#include <iostream>

class A
{
public:
        virtual void fun(int i) = 0; // FUN1
        void fun() { this->fun(123); } // FUN2
};

class B : public A
{
public:
        virtual void fun(int i) { std::cerr << i << std::endl; }
};

int main(int,char**)
{
        B b;
        b.fun();
}

为什么我不能在派生类上调用FUN2? g ++给出了一个错误:

main.cpp:19:8:错误:没有匹配函数来调用'B :: fun()'


编辑:请注意, 纯虚函数问题的重载是不同的。 我不想重写方法。


In the example below I have a abstract class with pure virtual method (aka FUN1) and a normal method (aka FUN2).

#include <iostream>

class A
{
public:
        virtual void fun(int i) = 0; // FUN1
        void fun() { this->fun(123); } // FUN2
};

class B : public A
{
public:
        virtual void fun(int i) { std::cerr << i << std::endl; }
};

int main(int,char**)
{
        B b;
        b.fun();
}

Why can't I call FUN2 on derived class? g++ gives an error:

main.cpp:19:8: error: no matching function for call to ‘B::fun()’


EDIT: note that Overload of pure virtual function question is different. I don't want to override methods.


原文:https://stackoverflow.com/questions/29595028
更新时间:2023-09-11 11:09

最满意答案

语法不允许var()表达式的第一个参数是除硬编码的单个自定义属性名称以外的任何其他参数。 这意味着您无法选择使用CSS在var()表达式中引用哪个定制属性,因为它不接受属性名称的字符串(或返回字符串的attr()表达式)。 您需要使用JS设置包含var()表达式的值。


The grammar does not permit the first argument of a var() expression to be anything but a single custom property name that is hardcoded. This means that you cannot choose which custom property to reference in a var() expression using CSS, since it doesn't accept a string (or an attr() expression returning a string) for a property name. You'll need to set the value containing the var() expression using JS.

相关问答

更多
  • 没有必要将样式内联在Javascript代码中。 由于您已经提供了id ,因此您只需在CSS文件或style元素中添加样式即可 #pastePhotos { display: inline-table; } 但是,主要问题似乎是缺少img和input元素的样式。 为此,您必须添加一个 #pastePhotos img, #pastePhotos input { display: table-cell; } 并将它们包装在table-row的附加div中 imageHTML += '
  • 你想要的与Ruby中method missing类似,在这里你定义了一个函数来处理对未定义方法的调用。 正如你可以在这里阅读: Javascript是否有类似Ruby的method_missing特性? JavaScript没有类似的东西,但有一个关于ES6的提议: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy What you want is similar to metho ...
  • 也许你可以从一个可观察对象中创建一个流,然后在你的组件中订阅它,因此每次它改变你的组件都会相应地更新这个值: import { Injectable } from '@angular/core'; import {Subject} from 'rxjs/Subject'; @Injectable() export class ViewToggleService { leftVisible:boolean=true; // Observable boolean source private lef ...
  • 我认为一个非常简单和干净的方法是创建一个数组。 var caja:Array = new Array(); for (i = 0; i < 5; i++) { caja[i] = new HTMLTextBlock(); } 请记住,数组中的第一个条目从0开始并且不是1(即caja [0])。 希望这可以帮助 :) I think a very simple and clean way of achieving this is creating an array. var caja:Array ...
  • var意味着静态类型被推断 - 在你的情况下它完全等同于 A a1 = new A(); 所有的约束仍然完全静态完成。 如果您查看生成的代码,它将与上述声明完全相同。 dynamic意味着使用a2所有表达式都将在执行时而不是编译时绑定,因此它可以动态地运行。 编译器不会检查Foo方法是否存在 - 行为是在执行时确定的。 实际上,如果对象实现了IDynamicMetaObjectProvider它可以决定在执行时如何处理调用,响应任何方法调用(或其他类型的使用) - 换句话说,不必是一个称为“真实的”方法F ...
  • 语法不允许var()表达式的第一个参数是除硬编码的单个自定义属性名称以外的任何其他参数。 这意味着您无法选择使用CSS在var()表达式中引用哪个定制属性,因为它不接受属性名称的字符串(或返回字符串的attr()表达式)。 您需要使用JS设置包含var()表达式的值。 The grammar does not permit the first argument of a var() expression to be anything but a single custom property name tha ...
  • Javascript中没有静态属性,只存在动态属性访问。 无论您在源代码文件中添加什么语法,都会以相同的方式查询属性。 使用jshint为您的JS文件推荐良好的源代码约定: http://jshint.com/ 点符号总是建议。 只有当您的Javascript属性没有在JS语法中传递的id时才使用引号符号。 There are no static properties in Javascript, only dynamic property accessing exists. Properties are ...
  • 是的,如果没有设置,可以取消设置变量(只不过是一个可变属性)。 取消设置变量可归结为从包含属性列表的哈希表中删除条目。 从Hashtable#remove(Object key)的文档Hashtable#remove(Object key) : 从此哈希表中删除键(及其对应的值)。 如果密钥不在哈希表中,则此方法不执行任何操作。 Yes it is ok to unset a variable (which is nothing more than a mutable property) if it is ...
  • Firebird中没有这样的功能。 您将需要创建(并且最好)生成将引用硬编码的所有字段的触发器。 如果基础表发生更改或验证要求,则需要重新创建触发器以将添加或删除的字段考虑在内。 There is no such feature in Firebird. You will need to create (and preferably) generate triggers that will reference all fields hard coded. If the underlying table ch ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。