摘要: 今天看书,看到这个例子感觉不错。抄下来,兴许以后能用上。先给个例子吧:随意的一个字符串,比如pots * pans,本程序会输出stop * snap下面给出代码,大家可以根据自己的需要来更改。 1 // StandLibP476.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <string> 7 8 using namespace std; 9 10 int _tmain(int argc, _TCHAR* argv[])11 { 阅读全文
posted @ 2012-04-04 19:16 ziyoudefeng 阅读(1177) 评论(1) 推荐(0) 编辑
摘要: 由于是疑问贴,所以直接上代码:<代码中红色部分有疑问> 1 // StandLibP307.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <iostream> 6 #include <string> 7 #include <vector> 8 #include <functional> 9 #include <algorithm>10 using namespace std;11 12 13 class Person {14 1 阅读全文
posted @ 2012-04-02 16:43 ziyoudefeng 阅读(899) 评论(0) 推荐(0) 编辑
摘要: 今天看C++ 标准程序库里面讲到说map[key] = value;这种方式效率低,原因是新元素必须先使用default构造函数将实值(value)初始化,而这个初值马上又被真正的value给覆盖了。然后就想自己测试一下,下面是自己的测试代码,然后后面有自己对运行结果的不解。1、定义一个value型别,供map中使用 1 #pragma once 2 #include <iostream> 3 4 class TestMapSec 5 { 6 public: 7 TestMapSec(void) { std::cout << "default construc 阅读全文
posted @ 2012-04-01 17:45 ziyoudefeng 阅读(2352) 评论(4) 推荐(1) 编辑
摘要: 今天看了看Effective C++中文版第2版导读部分,里面说了不少东西,其中就包括标题里的这些概念。感觉自己对这些概念还不是很熟悉,于是摘抄一些内容放到博客里,以方便自己做笔记,回头记忆。1、声明与定义 所谓声明(declaration),是用来将一个object、function、class或template的型别名称告诉编译器。声明式并不带有细节信息。下面统统都是声明: extern int x; // object declaration int numDigits( int number ); // function declaration class Cl... 阅读全文
posted @ 2012-03-29 16:44 ziyoudefeng 阅读(1898) 评论(2) 推荐(2) 编辑
摘要: 先给一个小程序,大家猜一下结果是什么: 1 // StandLibP112.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <vector> 6 #include <algorithm> 7 #include <iostream> 8 9 using namespace std;10 11 int _tmain(int argc, _TCHAR* argv[])12 {13 14 vector<int> vec;15 16 for ( int i = 0 阅读全文
posted @ 2012-03-28 20:00 ziyoudefeng 阅读(2049) 评论(0) 推荐(1) 编辑
摘要: C++规定了1.函数模板作友元,但函数模板的参数和类模板的参数无关 对所有实例化类都是友元就是这种写法tempalate<typename valtype>class A{ template <typename T>friend std::ostream& operator<<( std::ostream &, const TemplateClass<T> &); }2.函数模板作友元,且用到了相应类模板的参数 那么它不是所有实例化类的友元,只是特定于一个实例化的类就是这种写法tempalate<typename v 阅读全文
posted @ 2012-03-23 11:09 ziyoudefeng 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 之前没有碰到过这类情况,也不知道实际工程中有什么奥妙,先来一个小的测试例子看一下运行结果: int a = 1; int b = 2; int *tmp = &a; int *p = tmp;// 第二种情况:int *&p = tmp;(此既是指向指针的引用) p = &b; *p = 5;1、测试此时的a, b , *tmp, *p分别是什么: a = 1, b = 5, *tmp = 1, *p = 5;2、如果是上述第二种情况,即指向指针的引用,那么这些变量又该是什么值呢?答案是: a = 1, b = 5, *tmp = 5, *p = 5; 这是因为指向指针 阅读全文
posted @ 2012-03-23 10:56 ziyoudefeng 阅读(2198) 评论(5) 推荐(0) 编辑
摘要: 一个类A定义如下:template <typename valType>class A {private: valType _val;};然后主要的问题是下面两个拷贝构造函数的区别: 第一种构造: template <typename valType> inline A<valType>::A( const valType &val ) { _val = val; } 第二种构造: template <typename valType> inline A<valType>::A( const valType &val 阅读全文
posted @ 2012-03-21 22:21 ziyoudefeng 阅读(1130) 评论(2) 推荐(1) 编辑
摘要: 第一段解读: 1、文章的目的:We are interested in tracking changes in large-scale data by periodically creating an agglomerative clustering and examining the evolution of clusters (communities) over time. 2、数据:the NEC CiteSeer database, a linked network of >250,000 papers. 3、前提条件:Tracking changes over time req 阅读全文
posted @ 2012-03-20 17:42 ziyoudefeng 阅读(1095) 评论(0) 推荐(0) 编辑
摘要: 一:先说虚拟函数的静态决议(Static Resolution) 在两种情况下,虚拟函数机制不会出现预期行为:1、在基类的constructor和destructor内;2、当我们使用的是基类的对象,而非基类对象的pointer 或 reference时。 上述第二种情况很好理解,第二种情况是C++多态机制的重要概念。第一种情况其实也很简单,但我才刚开始学习C++,怕以后自己会不小心把一些虚函数写在constructor 或 destructor里,固写此文章记录一下,下面给出第一种情况的解释: -----------------摘抄Essential C++解释开始----------... 阅读全文
posted @ 2012-03-20 14:36 ziyoudefeng 阅读(504) 评论(0) 推荐(0) 编辑