易截截图软件、单文件、免安装、纯绿色、仅160KB

初始化函数中的虚函数调用( C++ vs python )

代码+结果,不做解释
当然,对于python没有virtual function一说,估计当作对比一个例子看看吧。
#include <iostream>
using namespace std;
class base
{
public:
virtual void foo() { cout << "base" << endl; }
base() { foo() ;}
};
class derive: public base
{
public:
derive() { foo(); }
virtual void foo() { cout << "derive" << endl; }
};
int main()
{
derive d;
return 0;
}

结果:
base
derive
class base(object):
def __init__( self ):
self.foo()
def foo( self ):
print "base"
class derive( base ):
def __init__( self ):
super( derive , self ).__init__()
self.foo()
def foo( self ):
print "derive"
d = derive()

结果:
derive
derive


相关文档:

C/C++: 十六进制转10进制源码 收藏

C/C++: 十六进制转10进制源码
收藏



view plain
copy to clipboard
print
?
int
 hex_char_value(
char
 c)  
{  
    if
(c >= 
'0'
 && ......

Java与C++的多态

没有必要用一堆绕口的形容词来描述什么叫多态,只举出几个关键点。
    设:gun为父类,shootgun和pistol为gun的子类。
    Java:
    class gun {
        void shoot() {
          ......

C/C++ 与运算和或运算转换大小写

// & 与,将指定位置设置为0     | 或,将指定位置设置为1
//注: 只针对纯字母的情况
#include <stdio.h>
#include <string>
int main()
{
char str[6] = "xxing";
std::string str1 = "INGXX";
for(int i = 0; i < 5; i++)
{
str[i] &= 0xdf; ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号