码迷,mamicode.com
首页 >  
搜索关键字:friend    ( 1299个结果
一步一步学习C++(类)之友元函数
友元函数使用说明 1)必须在类的说明中说明友元函数,说明时以关键字friend开头,后跟友元函数的函数原型,友元函数的说明可以出现在类的任何地方,包括在private和public部分; 2)注意友元函数不是类的成员函数,所以友元函数的实现和普通函数一样,在实现时不用"::"指示属于哪个类,只有成员函数才使用"::"作用域符号; 3)友元函数不能直接访问类的成员,只能访问对象成员, 4)友元函数可以访问对象的私有成员,但普通函数不行; 5)调用友元函数时,在实际参数中需要指出要访问的对象, 6)类与类之间的...
分类:编程语言   时间:2015-04-09 15:40:14    阅读次数:192
effective c++ 笔记 (7)
//---------------------------15/04/08---------------------------- //#23   宁以non_member、non_friend替换member函数 {     class WebBrowser     {     public:         ...         void clearCache();...
分类:编程语言   时间:2015-04-09 08:55:53    阅读次数:160
C++中bitset的实现(引用类的使用)
#include #include #define CHAR_BIT 8 using namespace std; template class bitset { typedef unsigned long _Ty; friend ostream & operator &_R) { for(size_t _P=_N;_P>0;) _O<<(_R.test(--_P)?'1...
分类:编程语言   时间:2015-04-08 11:04:38    阅读次数:160
C++字典的线性表实现。
#include #include using namespace std; struct SchoolNo { int no; friend bool operator == (const SchoolNo &school1,const SchoolNo &school2) { return (school1.no==school2.no); } friend ostrea...
分类:编程语言   时间:2015-04-07 15:42:48    阅读次数:123
C++中setbit的实现(没有使用引用技术)
#include #include #define CHAR_BIT 8 using namespace std; template class bitset { typedef unsigned long _Ty; friend ostream & operator &_R) { for(size_t _P=_N;_P>0;) _O<<(_R.test(--_P)?'1...
分类:编程语言   时间:2015-04-07 15:40:31    阅读次数:285
14.3. 算术操作符的重载
#include#includeusing namespace std;class sales_item{ friend istream& operator>>(istream &,sales_item&); friend ostream& operator<<(ostream&,const sal...
分类:其他好文   时间:2015-04-06 20:10:43    阅读次数:135
14.2. 输入和输出操作符重载
#include#includeusing namespace std;class sales_item{ friend istream& operator>>(istream &,sales_item&); friend ostream& operator>(istream& ism,sales_...
分类:其他好文   时间:2015-04-06 20:06:17    阅读次数:123
13.5.1. 定义智能指针类
#include #include#includeusing namespace std;//智能指针的使用//智能指针类class U_ptr{ friend class hashptr; int *ip;//在hashptr中实际的需要定义的指针成员 size_t use;//使用次数的计数 U...
分类:其他好文   时间:2015-04-06 17:12:42    阅读次数:163
重载Point
重载Point其中减法表示向量,乘法表示叉积struct Point{ double x,y; friend double operator*(const Point A,const Point B) { return A.x*B.y-A.y*B.x; } ...
分类:其他好文   时间:2015-04-02 20:33:02    阅读次数:144
作业3
上节课跟着老师学到了很多东西,了解到了C#的一些具体功能,并且将其与C++等编程语句进行了比较,发现了它的优势与不足。给我印象最深的是老师说的友元函数,也就是friend类,在一个类中定义了友元函数就可以把privite中的信息分享出去,这一点和C++是一样的。又譬如显式定义explicitly,也...
分类:其他好文   时间:2015-03-30 22:46:36    阅读次数:109
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!