Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterator not accessible because of private inheritance

I've created a new class that composes std::deque by private inheritance, i.e,

class B : private std::deque<A>
{ ... };

and in my source code I tried to use iterator of B, i.e.,

B::iterator it

The compiler error is

error C2247: 'std::deque<_Ty>::iterator' not accessible because 'B' uses 'private' to inherit from 'std::deque<_Ty>'

So the question is, how can I make the iterator accessible?

like image 308
segfault Avatar asked Sep 18 '25 23:09

segfault


1 Answers

You have to promote this iterator class.

Use using keyword in public section.

class B : private std::deque<A>
{ ... 
 public:
   using std::deque<A>::iterator;    
};

The same for other types as well as other functions from implementation base class(es).

like image 108
PiotrNycz Avatar answered Sep 21 '25 14:09

PiotrNycz