【发布时间】:2013-12-22 05:57:01
【问题描述】:
我目前在最新的 OSX 上使用 Clang 在 C++11 中构建一个静态库,遇到了一些对我来说似乎很奇怪的东西。
我有从 A 和 B 继承的 C 类。A 用作该类用户的公共接口,B 用作抽象实现,保存所有 A 实例通用的方法。我来自Java 世界,所以我将 A 视为接口,将 B 视为抽象类。
在 C 类中,我有一个从 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;
}
一切正常。我可以看到this->isCompressedFile() 中的日志语句被调用。如果我删除临时变量is_compressed_file 并在条件中直接调用this->isCompressedFile(),它们不会被调用。就好像方法不存在一样。
我错过了一些关于 C++ 的东西吗?这是一个 Clang 错误吗?我的 Java 背景是否让我感到困惑?
【问题讨论】:
标签: c++ oop inheritance c++11 clang