Hi,
the following code snippet compiles fine and behaves as expected, but I
wonder whether that behavior is guaranteed by the standard:
#include <iostream>
struct base
{
struct iterator
{
iterator(base & b) : _base(b) { }
base & _base;
};
};
struct derived : public base
{
struct iterator : public base::iterator
{
iterator(derived & d) : base::iterator(d) { }
};
void print() { std::cout << "derived::print()" << std::endl; }
};
int main(int, char**)
{
derived d;
derived::iterator i( d );
static_cast<derived &>(i._base).print();
return 0;
}
Why does that static_cast from `base' to `derived' succeed? Would this
code still work in case multiple inheritance?
Best regards,
Peter
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]