rui*_*eco 2 c++ oop inheritance clang c++11
我目前在最近的OSX上使用Clang在C++ 11中构建一个静态库,并且遇到了一些对我来说很奇怪的东西.
我有从C和B继承的C类.A用作类的用户的公共接口,B用作抽象实现,包含所有A实例共有的方法.我来自Java世界所以我将A视为接口,将B视为抽象类.
在类CI中有一个从B继承的方法,它调用C中定义的两个私有方法.这就是古怪.如果我实现这样的继承方法:
bool EPubParser::isCorrectFileType() {
bool has_correct_file_type = false;
bool is_compressed_file = this->isCompressedFile();
if (this->hasRightExtension() && is_compressed_file) {
has_correct_file_type = true;
}
if (has_correct_file_type) {
LOG(DEBUG)<< "Has correct file type. " << endl;
} else {
LOG(DEBUG)<< "Does not have correct file type. " << endl;
}
return has_correct_file_type;
}
Run Code Online (Sandbox Code Playgroud)
一切正常.我可以看到this->isCompressedFile()被调用的日志语句.如果我删除临时变量is_compressed_file并this->isCompressedFile()直接在条件中调用,则不会调用它们.就好像该方法不存在一样.
我错过了一些关于C++的东西吗?这是一个Clang bug吗?我的Java背景是否让我失望?