Can c++ internal (inner) classes be defined outside of external classes?

Asked 2 years ago, Updated 2 years ago, 76 views

Implementing list and vector

I don't want to define itterator, which is an internal class of two classes, so I define it separately.

I'd like to refer to it, is there a way?

c++ data-structure

2022-09-22 15:22

1 Answers

typedef allows you to put a type name inside the class.

class Iterator {
    // ...
};

class list {
public:
    typedef Iterator iterator;
};

class vector {
public:
    typedef Iterator iterator;
};

Alternatively, you can define an externally declared class in the following ways:

class vector {
public:
    class iterator;
};

class vector::iterator {
// ...
};


2022-09-22 15:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.