String类的简单实现:
1、在拷贝构造函数和赋值运算符重载这两个函数中有浅拷贝和深拷贝的问题
2、要对输入输出函数重载
3、赋值运算符重载有两种方式。注意在采用交换实现的时候函数的参数只能是临时变量
class String
{
friend ostream& operator<<(ostream& os, String& s);
friend istream& opera...
分类:
其他好文 时间:
2016-08-23 13:23:36
阅读次数:
159
本来这篇博客是不打算写的,内容不是很难,对于我自己来讲,更多的是为了突出细节。 所谓template friend functions,就是使友元函数本身成为模板。基本步骤:1,在类定义的前面声明每个模板函数。eg:template <typename T> void counts(); templ ...
分类:
其他好文 时间:
2016-08-22 23:30:31
阅读次数:
281
友元函数和友元类在实际开发中较少使用,想快速学习C++的读者可以跳过本节。 一个类中可以有 public、protected、private 三种属性的成员,通过对象可以访问 public 成员,只有本类中的函数可以访问本类的 private 成员。现在,我们来补充介绍一个例外——友元(friend ...
分类:
编程语言 时间:
2016-08-22 21:32:30
阅读次数:
236
描述 JR有很多双筷子。确切的说应该是很多根,因为筷子的长度不一,很难判断出哪两根是一双的。JR家里来了K个客人,JR留下他们吃晚饭。加上JR,JR的girl friend和JR的朋友内涵,共K+3个人。每人需要用一双筷子。JR只好清理了一下筷子,共N根,长度为T1,T2,T3,……,TN.现在他想 ...
分类:
其他好文 时间:
2016-08-20 23:14:20
阅读次数:
206
A friend of mine came to me with her iPhone yesterday. She wanted to know how to clear search history in App “Maps”. She showed me the search history ...
分类:
其他好文 时间:
2016-08-20 17:38:27
阅读次数:
130
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston ...
分类:
其他好文 时间:
2016-08-20 12:56:18
阅读次数:
122
Parity Time limit: 2.0 secondMemory limit: 64 MB Now and then you play the following game with your friend. Your friend writes down a sequence consist ...
分类:
其他好文 时间:
2016-08-16 23:39:19
阅读次数:
198
今天看到流运算符重载的时候有几个疑问,一是为何在只需声明一次friend即可,而不是在两个类之间都使用friend,二是为何不能重载为成员函数。第一个问题:都使用friend,函数需要访问两个类的私有成员第二个问题:重载为了成员函数,但应用上出现了问题,详情见代码。usingstd:..
分类:
其他好文 时间:
2016-08-14 14:48:25
阅读次数:
158
You are playing the following Flip Game with your friend: Given a string that contains only these two characters: + and -, you and your friend take tu ...
分类:
其他好文 时间:
2016-08-14 12:59:10
阅读次数:
181
题目: You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each ...
分类:
其他好文 时间:
2016-08-10 12:26:32
阅读次数:
134