假设您有基类Unix_tree
和派生类,Unix_tree_type1
依此Unix_tree_type2
类推。为什么我不能投射Unix_tree
到Unix_tree_type
...?有没有办法进行这样的演员表?派生类包含抽象方法的实现,它们的目标是以不同的方式打印基类中包含的数据。谢谢。
class Unix_tree
{
public:
Unix_tree ()
{
tree_it.tree = &tree;
}
Unix_tree(const Unix_tree& utree) : num_of_files(utree.num_of_files), tree(utree.tree), tree_it(utree.tree_it)
{
tree_it.tree = &tree;
};
int num_of_files;
map<int, pair<int, string> > names;
vector<pair<int, int> > edges;
Tree< pair<int, string> > tree;
TreeIterator< pair<int, string> > tree_it;
string input_format;
string output_format;
static Unix_tree* load_tree(istream& input_info);
void load_names(istream& input_info);
void load_tree_nodes(vector<int>& levels);
Unix_tree* convert(string format);
virtual void load(istream& input_info) = 0;
virtual void print_function(const Tree<pair<int, string> >* node, const vector<bool>& visited ) = 0;
void print_tree();
};
class Unix_tree_type1 : public Unix_tree
{
public:
void load(istream& input_info);
void print_function(const Tree<pair<int, string> >* node, const vector<bool>& visited);
};