简体   繁体   中英

reference to another class on initialization

I have a class who do some things.

class ClassA
{

public:
    ClassA()
    { 
        for (unsigned i = 0; i < MAX_PROCESS_ID; ++i) 
            processDB[i] = 0; 
    };

    virtual ~ClassA(){ };

    int     create(int pID);
    bool    check(int pID);
    bool    kill(int pID);
    int     returnpDB(int pID);

private:
    bool saveProcess(int pID, int type);

protected:
    int pDB[MAX_PROCESS_ID];
};

and what i want to do it's initialize this class from another one and keep a reference.

for example:

class classB
{

public:
    classB(){};
    virtual ~classB(){ };

private:

protected:
    classA      &pm;
};

how can i do this? (if I can!)

thanks!

class classB
{

public:
    classB(classA& ref):pm(ref){};
    virtual ~classB(){ };

private:

protected:
    classA      &pm;
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM