C++ Class Definition Embedded Classes

Description

C++ Class Definition Embedded Classes

#include <iostream>
using namespace std;

class MyClass {/*from   w ww . j  a  v  a2s. c  om*/
private:
    class Connection;
public:
    void HardWork();
};
class MyClass::Connection {
protected:
    friend class MyClass;
    void Connect();
    Connection() {}
    ~Connection() {}
};
void MyClass::HardWork() {
    Connection c;
    c.Connect();
    cout << "Connected" << endl;
}
void MyClass::Connection::Connect() {
    cout << "Connecting..." << endl;
}
int main(int argc, char *argv[])
{
    // MyClass::Connection myconnect;
    MyClass comp;
    comp.HardWork();
    return 0;
}



PreviousNext

Related