は(何のコードが省略されていない)私のプロジェクトへの完全なコードです:マークラインでなぜコンパイラは「Static_castから関連していないもの」と言っていますか?
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
typedef enum{
MAJOR_BUTTON_IGNORED_FIRST = 0,
MAJOR_BUTTON_BLOCKS,
MAJOR_BUTTON_IGNORED_LAST,
}MAJOR_BUTTON_TYPE;
typedef enum{
BLOCK_IGNORED_FIRST = 0,
BLOCK_ORDINARY_SMASHABLE,
BLOCK_IGNORED_LAST,
}THING_TYPE;
class Datar{
private:
public:
MAJOR_BUTTON_TYPE majorType;
std::string majorButtonString;
std::vector<THING_TYPE>thingTypes;
std::unordered_map<THING_TYPE, std::string>thing2String;
Datar(){
}
virtual ~Datar(){};
virtual void initDatar(){};
};
class DatarBlock : public Datar{
private:
public:
virtual void initDatar(){
majorType = MAJOR_BUTTON_BLOCKS;
majorButtonString = "MajorButtonNames::blocks";
}
};
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
DatarBlock* db = new DatarBlock();
Datar* blah = static_cast<Datar*>(db); //Compiler error here ****
return 0;
}
、言うコンパイルエラーがあります:
main.cppに:62: 19:「DatarBlock *」から が継承によって関連していない「DATAR *」にstatic_castを、
を許可されていないのはなぜエラーとしてコンパイラのレポートそれをしませんか?
編集:私はXcodeの7.2(LLVM 7.0)を使用しています、C++標準ライブラリは= libcの++(C++ 11のサポートとLLVM標準ライブラリ)、C++言語の方言= GNU ++ 11
[再生できません](http://rextester.com/TPGX82687)どのコンパイラを使用していますか? – songyuanyao
@songyuanyao私はXcode 7.2(LLVM 7.0)、C++標準ライブラリ= libC++(C++ 11をサポートするLLVM標準ライブラリ)、C++言語の方言= GNU ++ 11を使用しています。 –
あなたが今削除したのと同じ質問を投稿するのはなぜですか? http://stackoverflow.com/questions/36785524/why-does-the-compiler-think-that-these-two-classes-are-not-related-by-inheritanc/ –