2012年6月14日
摘要: 需要注意的是操作符重载,赋值操作符必须返回*this;输入输出操作符不能作为类的成员函数,一般应声明为friend;关系操作符应定义为内联函数,也应为非成员函数;#include "stdafx.h"#include <iostream>using namespace std;class myClass{public: myClass(int ,int ,char*); ~myClass(); void printMem(); int get_len(); myClass &operator+(const myClass&); friend os 阅读全文
posted @ 2012-06-14 23:38 kunkka_ 阅读(123) 评论(0) 推荐(0) 编辑
摘要: #include <bitset>#include <iostream>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ bitset<30>myBitSet; myBitSet.set(0); myBitSet.reset(0); myBitSet |=1UL<<27; myBitSet &=~(1UL<<27); for (int i = 0;i<30;i++) { cout<<myBitSet[i]<<endl; } retu 阅读全文
posted @ 2012-06-14 22:57 kunkka_ 阅读(99) 评论(0) 推荐(0) 编辑
摘要: #include "stdafx.h"#include <iostream>using namespace std;#define ARRYLEN(arry)(sizeof(arry)/sizeof(arry[0]))template <class T>int ArryLen(T&arry){ return (sizeof(arry)/sizeof(arry[0]));}int _tmain(int argc, _TCHAR* argv[]){ int arry_1[100]; cout<<ARRYLEN(arry_1)<& 阅读全文
posted @ 2012-06-14 22:33 kunkka_ 阅读(185) 评论(0) 推荐(0) 编辑
  2012年6月13日
摘要: #include "stdafx.h"#include <iostream>using namespace std;class abstractClass{public: virtual void printFS() = 0; virtual int get_value() = 0;};class inheritClass:public abstractClass{public: inheritClass():m_value(0){}; virtual void printFS();//virtual int get_value();private: int m 阅读全文
posted @ 2012-06-13 23:11 kunkka_ 阅读(604) 评论(0) 推荐(0) 编辑
  2012年6月2日
摘要: #include "stdafx.h"#include <iostream>using namespace std;template<class T>class Operation{public: virtual void Algorithm() = 0;};template<class T>class Add:public Operation<T>{public: Add (T a , T b):m_a(a),m_b(b) { } void Algorithm() { cout<< (m_a + m_b)< 阅读全文
posted @ 2012-06-02 16:17 kunkka_ 阅读(112) 评论(0) 推荐(0) 编辑
摘要: dynamic_cast 动态类型转换,必须有虚函数。#include "stdafx.h"#include <iostream>using namespace std;class Basic{public: virtual void funOfBasic(){cout<<"this is the basic's fun"<<endl;}};class Derived:public Basic{public: virtual void funOfDerived(){cout<<"this 阅读全文
posted @ 2012-06-02 12:47 kunkka_ 阅读(154) 评论(0) 推荐(0) 编辑
  2012年5月30日
摘要: 近期遇到一些困惑。行动的过程中瞻前顾后,不能酣畅淋漓。困惑是因为模糊,业余时间把这些东西搞清楚。1、类何时需要自己的析构函数? 当类的构造函数在执行过程中申请了一些资源,销毁类的对象时需要收回这些资源。 一个相当经典的例子:#include <iostream>using namespace std;class String{public:String(const char*str);~String();explicit String(const String&str);String&operator=(const String&str);private: 阅读全文
posted @ 2012-05-30 22:11 kunkka_ 阅读(332) 评论(0) 推荐(0) 编辑
  2012年5月28日
摘要: 多个编译单元使用方式有两种: 方式一: 在头文件中: static const int buffSize = 100; // 方式二: 在头文件中:extern const int buffSize; 在对应的源文件中 const int buffSize = 100; // 如果在方式二的头文件中如下定义:extern const int buffSize = 100;就会报错,因为有重定义的可能。方式一为什么没有这种可能,因为static变量在编译时就分配了存储空间(全局数据区)。如果在头文件的函数体外定义了如下格式的全局变量,后果可能是灾难性的:static int bu... 阅读全文
posted @ 2012-05-28 22:44 kunkka_ 阅读(166) 评论(0) 推荐(0) 编辑
  2012年5月23日
摘要: classParent.h头文件#ifndef PARENT_H#define PARENT_Hclass classParent{public:classParent(){}protected:private:int inumOfParent;};#endif"classChild.h"头文件#ifndef CHILD_H#define CHILD_H#include "classParent.h"class classChild:public classParent{public:classChild(){}~classChild(){};priva 阅读全文
posted @ 2012-05-23 23:02 kunkka_ 阅读(141) 评论(0) 推荐(0) 编辑