成员职能

Member functions

本文关键字:成员      更新时间:2023-10-16

编译时,我在"void operation"一行遇到错误,因为我还没有定义Gate_ptr。我想在函数def中将"Gate_ptr"改为"Gate*"。但是,有没有办法保持我当前的风格?

  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;

首选此顺序:

 //forward decleration
class Gate;
//typedef based on forward dec.
typedef Gate* Gate_ptr; 
//class definition
class Gate
{
   public:
//...
};

Forwared声明,执行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;
};