CMALLET开始,ALPHABET(遵循google c++ style)

来源:互联网 发布:下载解压软件 编辑:程序博客网 时间:2024/05/15 15:49
/* * Copyright 2011 <qibaoyuan> *  * ===================================================================================== * *       Filename:  Alphabet.cc * *    Description:  source file for alphabet * *        Version:  1.0 *        Created:  2011年10月11日 20时12分01秒 *       Revision:  none *       Compiler:  gcc * *         Author:  qibaoyuan@126.com  *        Company:  ict,gucas * * ===================================================================================== */#include <cstdio>#include <map>#include <list>#include <string>using std::ostream;using std::map;using std::list;using std::string;using std::make_pair;#include "types/Alphabet.h"#define DISALLOW_COPY_AND_ASSIGN(TypeName) \TypeName(const TypeName&); \void operator=(const TypeName&);// anonymous namespace is encouraged.namespace CMALLET_TYPES {  // define the alphabet class  template<typename T1, typename T2>    class Alphabet {      public:        explicit Alphabet() {          printf("default construction\n");        }        void Init();        int size();        ~Alphabet() {          printf("destrcting...\n");        }      private:        map<T1, int> __map;        bool growthStopped;        list<T2> entries;        // copy and assign func is disallowed        DISALLOW_COPY_AND_ASSIGN(Alphabet);     };  template<typename T1, typename T2>    void Alphabet<T1, T2>::Init() {      int i = 0;      __map.insert(make_pair("I", i++));      __map.insert(make_pair("am", i++));      __map.insert(make_pair("John", i++));  }  template<typename T1, typename T2>    int Alphabet<T1, T2>::size() {      return __map.size();  }}int main() {  using CMALLET_TYPES::Alphabet;  Alphabet<string, int> alphabet;  alphabet.Init();}

原创粉丝点击