会员职能

时间:2012-03-30 19:37:59

标签: c++ class compiler-errors member-functions

编译时,我在“void operation”行收到错误,因为我还没有定义Gate_ptr。我想在“函数def”中用“Gate *”交换“Gate_ptr”。但是,有没有办法保持我目前的风格?

  class Gate
    {
        public:
                Gate();
          void operation(Gate_ptr &gate_tail, string type, int input1, int input2=NULL);

        private:
                int cnt2;
                int input_val1, input_val2;
                int output, gate_number;
                int input_source1, input_source2;
                int fanout[8];
                Gate* g_next;
                string type;
};
typedef Gate* Gate_ptr;

2 个答案:

答案 0 :(得分:4)

首选此订单:

 //forward decleration
class Gate;

//typedef based on forward dec.
typedef Gate* Gate_ptr; 

//class definition
class Gate
{
   public:
//...
};

答案 1 :(得分:4)

转发声明,执行typedef,并定义类:

class Gate;
typedef Gate* Gate_ptr;

class Gate
{
    public:
            Gate();
            void operation(Gate_ptr &gate_tail, string type, int input1, int input2=NULL);

    private:
            int cnt2;
            int input_val1, input_val2;
            int output, gate_number;
            int input_source1, input_source2;
            int fanout[8];
            Gate* g_next;
            string type;
};
相关问题