我有以下代码:
#include <iostream>
struct Base {
int i_;
};
class El : protected Base {
public:
int get_i() const { return i_; }
void set_i(int i) { i_ = i; }
};
class It : protected Base {
public:
using pointer = const El*;
using reference = const El&;
reference operator*() const
{
return reinterpret_cast<reference>(*this);
}
pointer operator->() const
{
return reinterpret_cast<pointer>(this);
}
};
int main()
{
It it;
It* itp = ⁢
std::cout << *****(itp)->get_i() << "\n"; //ERROR
}
GCC 和 Clang++ 都无法调用operator*
or ,所以无论我尝试了多少次间接调用,最后一行都会operator->
出错。It doesn't have member function 'get_i'
标准是否保证这种不直观的行为?