谁能告诉我为什么这段代码的行为方式呢?查看代码中嵌入的评论......
我错过了一些非常明显的东西吗?
using System;
namespace ConsoleApplication3
{
public class Program
{
static void Main(string[] args)
{
var c = new MyChild();
c.X();
Console.ReadLine();
}
}
public class MyParent
{
public virtual void X()
{
Console.WriteLine("Executing MyParent");
}
}
delegate void MyDelegate();
public class MyChild : MyParent
{
public override void X()
{
Console.WriteLine("Executing MyChild");
MyDelegate md = base.X;
// The following two calls look like they should behave the same,
// but they behave differently!
// Why does Invoke() call …Run Code Online (Sandbox Code Playgroud) 想象一下标准的钻石继承.A类定义纯虚函数fx,B类定义fx的实现,C和D类对fx不执行任何操作.当试图在类D的实例上调用fx时,你会得到'模糊函数调用'错误,尽管只有一个fx实现.这可以通过以虚拟方式从A继承的B和C来解决.这是问题的正确解决方案吗?虚拟继承如何处理虚函数表的合并?
A --->乙---> d
\ --->Ç------ ^
一段时间后,发现了一个外观漂亮的框架,允许.net开发人员实现虚拟文件系统.我以为我已经给它添加了书签,但似乎我没有.
有谁知道这样做的任何框架?
编辑:这是一个提示......它有一个吸引人的,简短的名称,它是自己的域名.对不起,这就是我所能记住的:p
我正在扩展第三部分库提供的课程.该类,我们称之为Foo,有一个reset()方法可以调用,以重新启动Foo的行为.该reset()方法也由类内部使用.
class Foo
{
public:
void reset () {
/* ... */
}
void something () {
reset();
}
};
Run Code Online (Sandbox Code Playgroud)
到目前为止,我需要重载该reset()方法以重置我的其他功能:
class Bar : public Foo
{
public:
void reset() {
/* ...something... */
Foo::reset();
}
};
Run Code Online (Sandbox Code Playgroud)
不幸的是,由于该Foo::reset()方法不是虚拟的,通过调用Bar::something()我得到的Foo::reset()方法调用而不是Bar::reset().
是否有一种方法(不同于超载Foo::something())使其向后虚拟?
可能重复:
GNU编译器警告"类具有虚函数但非虚析构函数"
我正在为两个类编写一个接口,我在标题中收到警告.这是代码:
class GenericSymbolGenerator {
protected: // <== ok
~GenericSymbolGenerator(void) {}
public:
virtual GenericSymbolTableCollection* generateSymbolTableCollection(GenericSymbolTableCollection *gst) = 0;
GenericSymbolGenerator(void) {}
// ~GenericSymbolGenerator(void) {} // <== warning if used
};
class PascalPredefinedSymbolGenerator : public GenericSymbolGenerator {
protected:
~PascalPredefinedSymbolGenerator(void) {} // <== ok
public:
GenericSymbolTableCollection* generateSymbolTableCollection(GenericSymbolTableCollection *pst); // initializes *pst
PascalPredefinedSymbolGenerator(void) {}
// ~PascalPredefinedSymbolGenerator(void) {} <== warning if used
};
class PascalSymbolGenerator : public GenericSymbolGenerator {
protected:
~PascalSymbolGenerator(void) {} // <== ok
public:
GenericSymbolTableCollection* generateSymbolTableCollection(GenericSymbolTableCollection *st); // initializes st
PascalSymbolGenerator(void) {} …Run Code Online (Sandbox Code Playgroud) 我有两个mongoose模式如下:
var playerSchema = new mongoose.Schema({
name: String,
team_id: mongoose.Schema.Types.ObjectId
});
Players = mongoose.model('Players', playerSchema);
var teamSchema = new mongoose.Schema({
name: String
});
Teams = mongoose.model('Teams', teamSchema);
Run Code Online (Sandbox Code Playgroud)
当我查询团队时,我也会得到虚拟生成的小队:
Teams.find({}, function(err, teams) {
JSON.stringify(teams); /* => [{
name: 'team-1',
squad: [{ name: 'player-1' } , ...]
}, ...] */
});
Run Code Online (Sandbox Code Playgroud)
但我无法使用虚拟机获得此功能,因为我需要异步调用:
teamSchema.virtual('squad').get(function() {
Players.find({ team_id: this._id }, function(err, players) {
return players;
});
}); // => undefined
Run Code Online (Sandbox Code Playgroud)
实现这一结果的最佳方法是什么?
谢谢!
我有一个模板类,它有一堆纯虚拟和实现的虚函数.然后我让孩子继承这个班级.我想记录虚拟父类中的函数,并让子代在Doxygen中继承此文档.
例如(我不能发布真实的来源).
template <typename A>
class Parent {
/** Documentation
*/
virtual void pure() = 0;
/** More Docs
*/
virtual void notpure() {
...
}
};
Run Code Online (Sandbox Code Playgroud)
在包含所有正确包含的不同文件中(至少对于编译器而言)
class Child: public Parent<int> {
void pure() {
...
}
};
Run Code Online (Sandbox Code Playgroud)
然后我想要Doxygen为每个类生成文档,每个函数使用相同的文档,除非我重新记录被覆盖的函数.
我运行Ubuntu 14.04并使用存储库Doxygen 1.8.6以防万一.
谢谢
正如在C++ 编程语言中解释的那样:
virtual void push(char c) = 0;
virtual void pop() = 0;
Run Code Online (Sandbox Code Playgroud)
这个词virtual的意思是“以后可能会在这一个派生类中重新定义”
的=0语法说,一些类来源于栈必须定义的功能。
那么为什么=0需要符号呢?是不是说派生类一定要定义这个函数,也就是说没有的时候=0,一些派生类就没有强制定义这个方法?
我对此感到困惑,需要一些帮助。
是否可以在 Node.js 中创建虚拟目录?
例如,这些是根目录的内容。
.gitignore
README.md
main.js
node_modules
package.json
Run Code Online (Sandbox Code Playgroud)
当我启动节点应用程序时,它是否有可能xyz在根目录中虚拟创建一个目录?该目录实际上并不存在于计算机的文件系统中。
当节点应用程序运行时,如果任何模块(甚至fs)尝试读取文件系统,它将看到如下内容:
.gitignore
README.md
main.js
node_modules
package.json
xyz
Run Code Online (Sandbox Code Playgroud)
我只想在 Node.js 中实现这一点。并且,虚拟目录xyz中也会有文件。
我在谷歌上进行了全面搜索,但找不到任何东西。请问有人可以帮助我吗?
当覆盖 C++ 虚拟方法时,是否有一种方法可以在不指定确切基类名称的情况下调用基类方法,就像我们在 C# 中使用“base”关键字可以做到的那样?我知道这可能与多重继承发生冲突,但我想知道是否有更现代的 C++ 版本引入了这种可能性。我想做的是这样的:
class A
{
public:
virtual void paint() {
// draw something common to all subclasses
}
};
class B : public A
{
public:
virtual void paint() override {
BASE::paint();
// draw something specific to class B
}
};
Run Code Online (Sandbox Code Playgroud)
我知道在 B::paint() 中我们可以调用 A::paint(),我只想知道是否有更“通用”的方法来调用基本方法而不显式引用 A 类。提前谢谢. 安德烈亚
virtual ×10
c++ ×6
inheritance ×2
methods ×2
node.js ×2
.net ×1
abstract ×1
asynchronous ×1
begininvoke ×1
class ×1
delegates ×1
doxygen ×1
eclipse ×1
filesystems ×1
fs ×1
function ×1
invoke ×1
javascript ×1
mongodb ×1
mongoose ×1
overriding ×1
pure-virtual ×1