以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  期货人生  (http://weistock.com/bbs/list.asp?boardid=7)
----  [原创]C++ 类成员变量  (http://weistock.com/bbs/dispbbs.asp?boardid=7&id=57685)

--  作者:z7c9
--  发布时间:2013/10/17 15:53:46
--  [原创]C++ 类成员变量

#include <iostream>
#include <vector>
#include <memory>
#include <string>
#include <list>
#include <map>
#include <vld.h>

using namespace std;

class Some{
public:
    Some(){
        cout << "Some" << endl;
    }

    ~Some(){
        cout << "~Some" << endl;
    }
};

//class SomeClass{
//public:
//    SomeClass() : i(0),f(0),d(0),c(\'a\'),s("abc"),v(3,0),l(),m(),some(){
//        cout << "SomeClass" << endl;
//        m[0] = 0;
//        m[1] = 1;
//        m[2] = 2;

//        l.push_back(1);
//        l.push_back(2);
//        l.push_back(3);
//    }

//    ~SomeClass(){
//        cout << "~SomeClass" << endl;
//    }

//    void showMe(){
//        cout << "~~~~~~showMe~~~~~~~~" << endl;
//        cout << "i=" << i << endl;
//        cout << "f=" << f << endl;
//        cout << "d=" << d << endl;
//        cout << "c=" << c << endl;
//        cout << "s=" << s << endl;

//        cout << "v=";
//        for(int i=0;i<v.size();++i){
//            cout << v[i] << " ";
//        }
//        cout << endl;

//        cout << "m=";
//        for(int i=0;i<m.size();++i){
//            cout << i << " : " << m[i] << " ~ ";
//        }
//        cout << endl;

//        cout << "l=";
//        for(int i : l){
//            cout << i << " ";
//        }
//        cout << endl;
//        cout << "~~~~~~showMe~~~~~~~~" << endl;
//    }

//    int i;
//    float f;
//    double d;
//    char c;
//    string s;
//    vector<int> v;
//    map<int,int> m;
//    list<int> l;
//    Some some;
//};

//class SomeClass{
//public:
//    SomeClass() : i(new int(0)),f(new float(0)),d(new double(0)),c(new char(\'a\')),s(new string("abc")),v(new vector<int>(3,0)),m(new map<int,int>),l(new list<int>),some(new Some){
//        cout << "SomeClass" << endl;

//        (*m)[0] = 0;
//        (*m)[1] = 1;
//        (*m)[2] = 2;

//        l->push_back(1);
//        l->push_back(2);
//        l->push_back(3);
//    }

//    ~SomeClass(){
//        cout << "~SomeClass" << endl;
//        delete i;
//        delete f;
//        delete d;
//        delete c;
//        delete s;
//        delete v;
//        delete m;
//        delete l;
//        delete some;
//    }

//    void showMe(){
//        cout << "~~~~~~showMe~~~~~~~~" << endl;
//        cout << "i=" << *i << endl;
//        cout << "f=" << *f << endl;
//        cout << "d=" << *d << endl;
//        cout << "c=" << *c << endl;
//        cout << "s=" << *s << endl;

//        cout << "v=";
//        for(int i=0;i<v->size();++i){
//            cout << (*v)[i] << " ";
//        }
//        cout << endl;

//        cout << "m=";
//        for(int i=0;i<m->size();++i){
//            cout << i << " : " << (*m)[i] << " ~ ";
//        }
//        cout << endl;

//        cout << "l=";
//        for(int i : *l){
//            cout << i << " ";
//        }
//        cout << endl;
//        cout << "~~~~~~showMe~~~~~~~~" << endl;
//    }

//    int *i;
//    float *f;
//    double *d;
//    char *c;
//    string *s;
//    vector<int> *v;
//    map<int,int> *m;
//    list<int> *l;
//    Some *some;
//};

//class SomeClass{
//public:
//    SomeClass(int &i,float &f,double &d,char &c,string &s,vector<int> &v,map<int,int> &m,list<int> &l,Some &some) : i(i),f(f),d(d),c(c),s(s),v(v),m(m),l(l),some(some){
//        cout << "SomeClass" << endl;

//        m[0] = 0;
//        m[1] = 1;
//        m[2] = 2;

//        l.push_back(1);
//        l.push_back(2);
//        l.push_back(3);
//    }

//    ~SomeClass(){
//        cout << "~SomeClass" << endl;
//    }

//    void showMe(){
//        cout << "~~~~~~showMe~~~~~~~~" << endl;
//        cout << "i=" << i << endl;
//        cout << "f=" << f << endl;
//        cout << "d=" << d << endl;
//        cout << "c=" << c << endl;
//        cout << "s=" << s << endl;

//        cout << "v=";
//        for(int i=0;i<v.size();++i){
//            cout << v[i] << " ";
//        }
//        cout << endl;

//        cout << "m=";
//        for(int i=0;i<m.size();++i){
//            cout << i << " : " << m[i] << " ~ ";
//        }
//        cout << endl;

//        cout << "l=";
//        for(int i : l){
//            cout << i << " ";
//        }
//        cout << endl;
//        cout << "~~~~~~showMe~~~~~~~~" << endl;
//    }

//    int &i;
//    float &f;
//    double &d;
//    char &c;
//    string &s;
//    vector<int> &v;
//    map<int,int> &m;
//    list<int> &l;
//    Some &some;
//};

class SomeClass{
public:
    SomeClass() : i(new int(0)),f(new float(0)),d(new double(0)),c(new char(\'a\')),s(new string("abc")),v(new vector<int>(3,0)),m(new map<int,int>),l(new list<int>),some(new Some){
        cout << "SomeClass" << endl;

        (*m)[0] = 0;
        (*m)[1] = 1;
        (*m)[2] = 2;

        l->push_back(1);
        l->push_back(2);
        l->push_back(3);
    }

    ~SomeClass(){
        cout << "~SomeClass" << endl;
    }

    void showMe(){
        cout << "~~~~~~showMe~~~~~~~~" << endl;
        cout << "i=" << *i << endl;
        cout << "f=" << *f << endl;
        cout << "d=" << *d << endl;
        cout << "c=" << *c << endl;
        cout << "s=" << *s << endl;

        cout << "v=";
        for(int i=0;i<v->size();++i){
            cout << (*v)[i] << " ";
        }
        cout << endl;

        cout << "m=";
        for(int i=0;i<m->size();++i){
            cout << i << " : " << (*m)[i] << " ~ ";
        }
        cout << endl;

        cout << "l=";
        for(int i : *l){
            cout << i << " ";
        }
        cout << endl;
        cout << "~~~~~~showMe~~~~~~~~" << endl;
    }

    shared_ptr<int> i;
    shared_ptr<float> f;
    shared_ptr<double> d;
    shared_ptr<char> c;
    shared_ptr<string> s;
    shared_ptr<vector<int>> v;
    shared_ptr<map<int,int>> m;
    shared_ptr<list<int>> l;
    shared_ptr<Some> some;
};

int main(){
//    int i(0);
//    float f(0);
//    double d(0);
//    char c(\'a\');
//    string s("abc");
//    vector<int> v;
//    map<int,int> m;
//    list<int> l;
//    Some some;

//    SomeClass someClass(i,f,d,c,s,v,m,l,some);
    SomeClass someClass;
    someClass.showMe();
}


--  作者:gz12345678gz
--  发布时间:2013/10/17 17:08:24
--  
高僧,解释下啊