0

编译时在“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;
4

2 回答 2

4

喜欢这个顺序:

 //forward decleration
class Gate;

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

//class definition
class Gate
{
   public:
//...
};
于 2012-03-30T19:47:06.563 回答
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;
};
于 2012-03-30T19:48:43.553 回答