欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商教学与活动专区期货人生 → [原创]C++ 类成员变量

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有2211人关注过本帖树形打印复制链接

主题:[原创]C++ 类成员变量

帅哥哟,离线,有人找我吗?
z7c9
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小飞侠 帖子:1882 积分:3310 威望:0 精华:15 注册:2010/3/15 13:11:56
[原创]C++ 类成员变量  发帖心情 Post By:2013/10/17 15:53:46 [只看该作者]

#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
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:325 积分:14838 威望:0 精华:0 注册:2012/2/24 10:32:45
  发帖心情 Post By:2013/10/17 17:08:24 [只看该作者]

高僧,解释下啊

 回到顶部