I decided to write a stupid code that doesn't work:
template <class T, class Container>
class reversible_stack : protected std::stack<T, Container>
{
public:
void reverse()
{
std::reverse(std::begin(c), std::end(c));
}
};
this->c is needed instead of c.
Yet there isn't any this needed here:
namespace a
{
class base
{
protected:
int i;
};
};
class derived : protected a::base
{
public:
void foo() { i; }
};
__attribute__ ((__visibility__ ("default"))) makes no difference.
You can see libstdc++ code here. What is the difference that makes this required?
EDIT: This is not a duplicate. See the following code:
namespace standard
{
template <typename T>
class container
{
protected:
int i;
};
template <typename T, typename Container = container<T>>
class base
{
protected:
Container c;
};
}
class derived : protected standard::base<int>
{
public:
void foo() { c; }
};
Notice how base doesn't need to inherit from container, just like stack doesn't need to inherit from deque (container). Yet this compiles.
Somebody is going to say "it's an implementation detail", but the variable name c is specified by the standard [23.2.3.1].