摘要: const成员函数作用1. 不能修改类的成员变量,同时不能调用类的非const成员函数。(const成员函数中,this的类型是一个指向const类类型对象的const指针,const成员函数返回*this作为一个const引用)。2. 提供了基于const的重载。const对象只能使用const成员函数。非const对象可以使用任一成员,但非const版本是一个更好的匹配。const形参:仅当函数形参是引用或指针时,可基于形参是指向const对象还是指向非const对象,实现函数重载。如果传递了const对象,则只有带const形参的版本才是调用的可行函数。如果传递的是非const对象,则两 阅读全文
posted @ 2013-08-13 21:10 虫不知 阅读(356) 评论(0) 推荐(0) 编辑
摘要: _cdecl(C Declaration的缩写)是C/C++和MFC程序默认使用的调用约定,因此可以省略,也可以在函数声明时加上_cdecl关键字来手工指定。采用_cdecl约定时,函数参数按照从右到左的顺序入栈,并且由调用函数者把参数弹出栈以清理堆栈。因此,实现可变参数的函数只能使用该调用约定,如函数printf()。由于每一个使用_cdecl约定的函数都要包含清理堆栈的代码,所以产生的可执行文件大小会比较大。例子: void Input( int &m,int &n);/*相当于void _cdecl Input(int &m,int &n);*/ _std 阅读全文
posted @ 2013-08-13 20:35 虫不知 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 1.What's the output of the following code?(MS_2013_Intern_2)class A{public: virtual void f() { coutf();}int main(){ A* a = new B(); a->f(); g(a); delete a ;}答案:B::f() A::f() const2.What's the output of the following code?(MS_2013_Intern_8) 1 #include 2 3 class A{ 4 public:... 阅读全文
posted @ 2013-08-13 16:47 虫不知 阅读(66) 评论(0) 推荐(0) 编辑