alaigle

prepare yourself to change the world!

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

随笔分类 -  C++

摘要:原文http://patmusing.blog.163.com/blog/static/135834960201038113714199/在编写C++程序的时候,偶尔需要用到前置声明(Forward declaration)。下面的程序中,带注释的那行就是类B的前置说明。这是必须的,因为类A中用到了类B,而类B的声明出现在类A的后面。如果没有类B的前置说明,下面的程序将不同通过编译,编译器将会给出类似“缺少类型说明符”这样的出错提示。代码一:// ForwardDeclaration.h#include <iostream>using namespace std;class B; 阅读全文
posted @ 2012-06-05 14:14 alaigle 阅读(14622) 评论(1) 推荐(4)

摘要:原文地址http://blog.csdn.net/guirenwang/article/details/2611355this指针只能在一个类的成员函数中调用,它表示当前对象的地址。下面是一个例子: void Date::setMonth( int mn ) { month = mn; // 这三句是等价的 this->month = mn; (*this).month = mn; }1. this只能在成员函数中使用。 全局函数,静态函数都不能使用this。 实际上,成员函数默认第一个参数为T*const register this。如: class A{public... 阅读全文
posted @ 2012-05-31 11:47 alaigle 阅读(408) 评论(0) 推荐(0)