如题,我想这个是语法问题,求大神回答一下,http://www.tuicool.com/articles/FfQ3Avr,这是c++得到同样的提示
关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
resharp使用得到这个提示virtual member call in constructor
收起
- 写回答
- 好问题 0 提建议
- 关注问题
微信扫一扫点击复制链接分享
- 邀请回答
- 编辑 收藏 删除 结题
- 收藏 举报
2条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
threenewbee 2015-10-14 14:48关注不要在构造函数中调用虚拟函数,这是因为虚拟函数是派生类定义的,而构造函数先于派生类创建之前被调用,此时派生类的状态不可知。
虽然编译器允许你写这样的代码,但是这是非常危险的。本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏举报
微信扫一扫点击复制链接分享
评论按下Enter换行,Ctrl+Enter发表内容
报告相同问题?
提交
- 2019-10-02 15:51an0423的博客 当在一个非sealed类的构造函数中调用一个virtual 方法的时候,vs会提示一个virtual member call in constructor的警告,如图:既然是警告那就说明此处可能会有坑,细究一下。首先需要知道:1、c#中对象的初始化顺序...
- 2015-09-21 17:37weixin_30340353的博客 http://stackoverflow.com/questions/119506/virtual-member-call-in-a-constructor (Assuming you're writing in C# here) When an object written in C# is constructed, what happens is that the initializers...
- 2015-10-14 10:11weixin_34310127的博客 1.构造函数的执行顺序是:基类--->派生类 2.如果虚方法被重写后,由于基类中调用了虚方法,此时调用的是最外层的被重写后的虚方法,此时可能会发生异常 ... protected virtual void DoSomethi...
- 2010-09-07 21:31weixin_30271335的博客 嗷嗷按,今天被问到在constructor/destructor中调用virtual member function的问题。答错了,很羞耻。 依稀记得在constructor/destructor调用virtual member function不好,就随口答道不能调用,可能会出错。 后来...
- 2016-01-26 00:24林尧彬的博客 谜题 在C#中,用virtual关键字修饰的方法(属性、事件)称为虚方法(属性、事件),表示该方法可以由派生类重写(override)。...比如下面这个例子: public class Puzzle { public Puzzle() ...
- 2019-05-03 16:15weixin_30721077的博客 Can we make copy constructor private?Yes, a copy constructor can be made ... When we make a copy constructor private in a class, objects of that class become non-copyable. This is particularly us...
- 2024-06-21 23:23Yongqiang Cheng的博客 Virtual Method (虚函数) - Static and Dynamic Binding (静态联编和动态联编) - Virtual Destructor (虚析构函数)
- 2021-01-21 15:27谜题 在C#中,用virtual关键字修饰的方法(属性、事件)称为虚方法(属性、事件),表示该方法可以由派生类重写... Name = Virtual member call in constructor; Solve(); } public virtual string Name { get;
- 2015-08-09 19:53mathZHA的博客 已经看过了 virtual function的一般实现模型:每一个 class 有一个 virtual table,内含该 class 中有作用的 virtual function的地址,然后每个object有一个vptr,指向 virtual table的所在. 为了支持 virtual function...
- 2021-05-14 09:14夏叶AI加油站的博客 说明一下,我用的是gcc7.1.0编译器,标准库源代码也是这个版本的。 本篇文章讲解c++中,构造函数的高级用法以及特殊使用情况。 1. 拷贝构造和移动构造区别 对于拷贝构造和移动构造,还是看一下这段代码: #include ...
- 2018-03-15 13:12
More Effective C++ 条款24 了解virtual function,multiple inheritance,virtual base classes,runtime type id
Unique-You的博客 1. 要实现C++的每一个语言特性,不同的编译器... 当通过对象指针或引用调用虚函数时,具体调用哪一个虚函数由指针或引用的动态类型决定,大部分编译器使用vtbls(virtual tables,虚函数表)和vptrs(virtual table pointe... - 2013-09-21 10:09DeepSea0920的博客 原文链接:http://www.artima.com/cppsource/pure_virtual.html The C++ Source ..."Pure Virtual Function Called": An Explanation by Paul S. R. Chisholm February 26, 2007
- 2019-06-18 21:48cuiyong_cn的博客 转 Inheritance — Multiple and Virtual Inheritance 文章目录转 [Inheritance — Multiple and Virtual Inheritance][1]Things you have to consider when you make design decisionsWhat does it mean to ...
- 2019-11-05 08:37大树青云的博客 我以这个概述开始:你不应该在 construction(构造)或 destruction(析构)期间调用 virtual functions(虚拟函数),因为这样的调用不会如你想象那样工作,而且它们做的事情保证会让你很郁闷。如果你转为 Java 或 ...
- 2022-05-11 10:40bitcarmanlee的博客 在阅读项目源码时,看到许多default关键字,我们先通过一个例子来说明default的用法。 class Person { private: string name; public: Person(string _name) : name(_name) {} }; int main(int argc, char ...
- 2007-06-15 11:23cleverwyq的博客 Description of the R6025 run-time error in Visual C++loadTOCNode(1, symptoms);The C++ program fails and reports the following run-time error:runtime error R6025- pure virtual function cal
- 没有解决我的问题, 去提问