初始化函数中的虚函数调用( 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
相关文档:
已经知道的,不说了...大家都知道的,可以问问,查查资料。这里又放些附加建议:
1.基本算数运算:
既然计算机里没有真正的整数,那么计算机里也没有真正的算数运算。
取值范围:
设a和b是两个占一样位宽的无符号整数,这种整数可取到最大值M ......
Python 的异常处理机制
Python代码
try:
raise Exception("a", "b")
except Exception,e:
print e
finally:
print "final"
('a', ......
Python内建异常体系结构
BaseException
+-- SystemExit
+-- KeyboardInterrupt
+-- GeneratorExit
+-- Exception
+-- StopIteration
+-- StandardError
| +-- BufferError
| +-- ArithmeticError
| | +-- FloatingPointError
| | +-- OverflowError
| ......
用了三种方法...
#if 0
void StringTokenize(const std::string& strSrc, const std::string& strDelimit, std::vector<std::string>& vecSub)
{
if (strSrc.empty() || strDelimit.empty())
{
throw "tokenize: empty string\n";
......
1、在C文件中调用C++文件中定义的文件
直接的方法是在C++ 文件的头部添加如下代码段:
extern "C"
{
int API(int A);
}
2、C++接口的方法
在C++中调用C的函数,在C头文件中加入如下代码:
#ifdef __cplusplus // 开始
exte ......