继承,如何使用在其下面定义的类

时间:2015-04-08 09:40:17

标签: c++ inheritance prototype

我在开始时对类 class FSM 进行原型设计,然后在另一个类 class Run 从名为 excute() 的其他类虚拟地继承了函数class operation。并且还应该继承在类 class FSM 中声明的静态变量 static vector<FSM_inside> myFSM并使用它。编译器对它不满意!  如何解决这个问题? 并谢谢...

代码:

  class FSM;
 class Run :public operations, public FSM
 {
 public:
string name;
void virtual excute()
{
    /////////////HERE is the problem /////////////////////
        for (int y = 0; y < myFSM.size(); y++) // compiler can't see the var(myFSM)
    // inside the FSM class, how to solve this ?
                if(myFSM[y].name==name)
                    {
                            flag=true;
                            myFSM[y].startFSM();
                        }   
}
  };






 class FSM_inside : public  Variables, public virtual transition
{
public:
       void parse()
       {
           if (temp.find("run") != string::npos)
        {
            removespaces(temp);
            temp.substr(temp.find("run")+3);
            t1.first.instructionList.push_back(new Run()); // t1 is a temp. so don't worry about it.

         }
       }

       void startFSM()
         {
           }
};






class FSM  //This is working, compiler doesn't complain about the Class FSM
{
public :
    static vector<FSM_inside> myFSM; // no problem
   void parse() // parser function calls the parser function inside FSM_inside and so on for start
       {
        FSM_inside temp;
            temp.parse();
            myFSM.push_back(temp);
        }
    void start(string d)
        {
            for (int y = 0; y < myFSM.size(); y++)
                if(myFSM[y].name==d)
                      myFSM[y].startFSM();
         }

};

1 个答案:

答案 0 :(得分:1)

对类进行原型设计并不足以从该类继承。为什么不改变类定义的顺序?首先放置FSM,然后运行。