*自动虚拟*功能 [英] *auto virtual* feature

查看:70
本文介绍了*自动虚拟*功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们可以做这样的事情,那不是很好吗:


class Funky {


public:auto virtual void doStuff(){

// dostuff

}


};


class MoreFunky:public Funky {


public:void doStuff(){

//做更多的东西

}


};


类AdvancedFunky:public MoreFunky {


public:void doStuff(){

//做高级的东西

}


};


main(){


AdvancedFunky f;

f.doStuff();

}

现在,致电* auto virtual * member doStuff()应该遵循相同的

逻辑作为继承链中的构造函数调用,i。即当调用

f.doStuff()时,我们从下到上执行了所有doStuff()函数:


Funky :: doStuff()

MoreFunky :: doStuff()

AdvancedFunky :: doStuff()

我认为这个功能可以为我们带来很多麻烦。

解决方案

" nenad" < NE *** @ medix.com.hr>在消息中写道

news:41 ************************** @ posting.google.c om ...

如果我们可以做这样的事情,那不是很好吗:

类Funky {

public:auto virtual void doStuff() {
// dostuff
}

};

类MoreFunky:public Funky {

public:void doStuff( ){
//做更多的东西
}

};

类AdvancedFunky:public MoreFunky {

公开: void doStuff(){
//做高级的东西
}

};

main(){

AdvancedFunky f;
f.doStuff();
}

现在,调用* auto virtual * member doStuff()应遵循与构造函数调用相同的逻辑在继承链中,我。即当调用
f.doStuff()时,我们从下到上执行了所有doStuff()函数:

Funky :: doStuff()
MoreFunky :: doStuff()
AdvancedFunky :: doStuff()

我认为这个功能可以为我们带来很多麻烦。




这是不必要的,也不太可能影响扑热息痛的销售额b / b
。此外,顶部的班级不是从高处发音另外一个班级的虚拟功能应该如何操作。


DW


nenad写道:

如果我们可以做这样的事情,那不是很好吗?
类Funky {

public:auto virtual void doStuff(){
// dostuff
}

};

课程更多朋友:公众时髦{

公开:虚假的做什么(){
//做更多的事情
}

};

类AdvancedFunky:public MoreFunky {

public:void doStuff(){
//做高级的东西
}

>};

main(){

AdvancedFunky f;
f.doStuff();
}

现在,调用* auto virtual * member doStuff()应该遵循与继承链中的构造函数调用相同的逻辑,i。即当调用
f.doStuff()时,我们从下到上执行了所有doStuff()函数:

Funky :: doStuff()
MoreFunky :: doStuff()
AdvancedFunky :: doStuff()

我认为这个功能可以为我们带来很多麻烦。




写这个有什么问题以下?


class Funky {

public:virtual void doStuff(){

std :: cout<< Funky :: doStuff()\ n;;

}

};


class MoreFunky:public Funky {

public:void doStuff(){

Funky :: doStuff();

std :: cout<< " MoreFunky :: doStuff()\ n";

}


};


class AdvancedFunky :public MoreFunky {

public:void doStuff(){

MoreFunky :: doStuff();

std :: cout<< AdvancedFunky :: doStuff()\ n;;

}

};


Michael Mellor


>我认为这个功能可以为我们带来很多麻烦。


这真的可以节省那么多吗?除了

在每个函数中写一行,我都看不出它节省了什么,即:


class Funky {

public:doStuff(){

// dostuff

}


};
< br $>
class MoreFunky:public Funky {


public:void doStuff(){

Funky :: dostuff();

//做更多的东西

}


};


类AdvancedFunky:public MoreFunky {$ / $

public:void doStuff(){

MoreFunky :: dostuff();

//做高级的东西

}


};


如果没有语言,这可以轻松实现你想要的行为

扩展名,没有虚拟功能。而且,它允许你

控制函数调用的顺序。假设你想按顺序执行




AdvancedFunky :: doStuff()

MoreFunky :: doStuff()

Funky :: doStuff()


然后只需将代码更改为:


class MoreFunky:public Funky {


public:void doStuff(){

//做更多的东西

Funky :: dostuff();

}


};


类AdvancedFunky:public MoreFunky {


public:void doStuff(){

//做高级的东西

MoreFunky :: dostuff();

}
< br $>
};


或您喜欢的任何其他混音。如何使用auto

virtual来实现这一目标?需要另一个关键字,例如反向自动虚拟

或复古虚拟?


Wouldn''t it be nice if we could do something like this:

class Funky{

public: auto virtual void doStuff(){
// dostuff
}

};

class MoreFunky: public Funky{

public: void doStuff(){
// do more stuff
}

};

class AdvancedFunky: public MoreFunky{

public: void doStuff(){
// do advanced stuff
}

};

main(){

AdvancedFunky f;
f.doStuff();
}
Now, call to *auto virtual* member doStuff() should follow the same
logic as a constructor call in inheritance chain, i. e. when calling
f.doStuff() we got all doStuff() functions executed from bottom up:

Funky::doStuff()
MoreFunky::doStuff()
AdvancedFunky::doStuff()

I think this feature could save us a lot of headache.

解决方案

"nenad" <ne***@medix.com.hr> wrote in message
news:41**************************@posting.google.c om...

Wouldn''t it be nice if we could do something like this:

class Funky{

public: auto virtual void doStuff(){
// dostuff
}

};

class MoreFunky: public Funky{

public: void doStuff(){
// do more stuff
}

};

class AdvancedFunky: public MoreFunky{

public: void doStuff(){
// do advanced stuff
}

};

main(){

AdvancedFunky f;
f.doStuff();
}
Now, call to *auto virtual* member doStuff() should follow the same
logic as a constructor call in inheritance chain, i. e. when calling
f.doStuff() we got all doStuff() functions executed from bottom up:

Funky::doStuff()
MoreFunky::doStuff()
AdvancedFunky::doStuff()

I think this feature could save us a lot of headache.



It is unnecessary and would not likely affect the sales of paracetamol
significantly. Furthermore, it is not for the class at the top to pronounce
from on high how another class''s virtual functions should operate.

DW


nenad wrote:

Wouldn''t it be nice if we could do something like this:

class Funky{

public: auto virtual void doStuff(){
// dostuff
}

};

class MoreFunky: public Funky{

public: void doStuff(){
// do more stuff
}

};

class AdvancedFunky: public MoreFunky{

public: void doStuff(){
// do advanced stuff
}

};

main(){

AdvancedFunky f;
f.doStuff();
}
Now, call to *auto virtual* member doStuff() should follow the same
logic as a constructor call in inheritance chain, i. e. when calling
f.doStuff() we got all doStuff() functions executed from bottom up:

Funky::doStuff()
MoreFunky::doStuff()
AdvancedFunky::doStuff()

I think this feature could save us a lot of headache.



What is the problem with writing the following?

class Funky{
public: virtual void doStuff(){
std::cout << "Funky::doStuff()\n";
}
};

class MoreFunky: public Funky{
public: void doStuff(){
Funky::doStuff();
std::cout << "MoreFunky::doStuff()\n";
}

};

class AdvancedFunky: public MoreFunky{
public: void doStuff(){
MoreFunky::doStuff();
std::cout << "AdvancedFunky::doStuff()\n";
}
};

Michael Mellor


> I think this feature could save us a lot of headache.

Would this really save that much? I don''t see what it saves other than
writing one line in each function, i.e. :

class Funky{

public : doStuff() {
// dostuff
}

} ;

class MoreFunky: public Funky{

public: void doStuff(){
Funky::dostuff() ;
// do more stuff
}

};

class AdvancedFunky: public MoreFunky{

public: void doStuff(){
MoreFunky::dostuff() ;
// do advanced stuff
}

} ;

This achieves the behavior you want quite easily without a language
extension and without virtual functions. Moreover, it allows you to
control the order of the functions calls. Suppose you want to have
them executed in order :

AdvancedFunky::doStuff()
MoreFunky::doStuff()
Funky::doStuff()

then just change the code to :

class MoreFunky: public Funky{

public: void doStuff(){
// do more stuff
Funky::dostuff() ;
}

};

class AdvancedFunky: public MoreFunky{

public: void doStuff(){
// do advanced stuff
MoreFunky::dostuff() ;
}

} ;

Or any other mix you prefer. How would this be accomplished with "auto
virtual"? Would be need another keyword such as "reverse auto virtual"
or "retro virtual"?


这篇关于*自动虚拟*功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆