上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 48 下一页
摘要: 友元函数不是类的成员函数,没有this指针,所以必须在参数表中显式列出每一个操作数。#include <iostream>using namespace std;class Test {public: int a; int b; Test(): a(2), b(3) {}; friend ostream& operator<< (ostream& out, const Test& t) { out << t.a << "hello" << t.b; return out; }};int ma 阅读全文
posted @ 2012-12-27 22:46 helloweworld 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 在词法分析中,有条规则:每个符号应该包含尽可能多的字符,被称为“贪心法”或“大嘴法”。 K&R表述如下:如果(编译器的)输入流截止至某个字符之前都已经被分解为一个个符号,那么下一个符号将包括从该字符之后可能组成一个符号的最长字符串。 如: a---b 被编译器解释为 (a--)-b 阅读全文
posted @ 2012-12-27 19:19 helloweworld 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 常成员函数不能改变数据成员!#include <iostream>using namespace std;class Test {private: int a;public: int geta() { return a++; //正确! } int getConst() const { return a++; //错误!常成员函数不能改变数据成员。 }};int main(void){ return 0;} 阅读全文
posted @ 2012-12-26 11:48 helloweworld 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 静态成员函数如何初始化#include <iostream>using namespace std;class Test {private: static int statica; int b;public:// Test(): statica(1) {}; //错误!static数据成员不能通过初始化列表初始化。 Test(): b(1) {statica = 1;}; //正确。};int main(void){ return 0;}#include <iostream>using namespace std;class Test {private: static 阅读全文
posted @ 2012-12-26 11:47 helloweworld 阅读(273) 评论(0) 推荐(0) 编辑
摘要: 1、友元的声明只能出现在类定义的内部,2、可以出现在类中的任何地方,3、友元不是类的成员函数!所以它的声明可以出现在类中任何地方,而不受声明前面的访问控制影响!以上几条可见下例子:#include <iostream>using namespace std;class TestPoint {private: int x; int y; friend int distanceOne(); //友元的声明可以出现在类内任何地方,它不是类的成员函数!public: friend int distanceTwo(); //友元的声明可以出现在类内任何地方,它不是类的成员函数!};int d 阅读全文
posted @ 2012-12-25 20:43 helloweworld 阅读(899) 评论(0) 推荐(0) 编辑
摘要: 这里重点介绍?: #include <iostream>using namespace std;int main(void){ int a = 2; int b = 3; a > b ? a++ : b++; cout << a << endl; cout << b << endl; return 0;}输出:24这里a>b为假,则直接执行b++,不执行a++. 阅读全文
posted @ 2012-12-25 18:40 helloweworld 阅读(183) 评论(0) 推荐(0) 编辑
摘要: 老版本有运算符 =- (现在是-=)这时,a=–1;有二义性! 阅读全文
posted @ 2012-12-24 20:53 helloweworld 阅读(609) 评论(0) 推荐(0) 编辑
摘要: /****************************************************# File : main.cpp# Author : lucasysfeng# Revision : 2014-10-13 17:04:43# Descripti... 阅读全文
posted @ 2012-12-23 20:29 helloweworld 阅读(992) 评论(0) 推荐(0) 编辑
摘要: /****************************************************************************** * 统计句子中的单词数。 * 算法:单词是用分隔符隔开的,因此,从开始遇到不为分割符的符号直到遇到分隔符,单词数加1. ************************************************************... 阅读全文
posted @ 2012-12-21 21:09 helloweworld 阅读(191) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>#include <string>#include <utility>#include <vector>#include <map>#include <cctype>using namespace std;int main(){ string str("HellowoLD"); for (string::iterator iter = str.begin();... 阅读全文
posted @ 2012-12-20 15:00 helloweworld 阅读(457) 评论(0) 推荐(0) 编辑
上一页 1 ··· 27 28 29 30 31 32 33 34 35 ··· 48 下一页