操作符重载
摘要:需要注意的是操作符重载,赋值操作符必须返回*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_
阅读(126)
推荐(0)
bitset
摘要:#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_
阅读(101)
推荐(0)
宏和template<class T>
摘要:#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_
阅读(193)
推荐(0)
类不能继承接口,只能实现接口
摘要:#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_
阅读(614)
推荐(0)
简单的策略模式,类模版
摘要:#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_
阅读(116)
推荐(0)
dynamic_cast
摘要: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_
阅读(157)
推荐(0)