Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 成员函数_C++_Class_Compiler Errors_Member Functions - Fatal编程技术网

C++ 成员函数

C++ 成员函数,c++,class,compiler-errors,member-functions,C++,Class,Compiler Errors,Member Functions,编译时,我在“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);

编译时,我在“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 declare,执行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;
};

不,编译器在编译代码之前必须知道类型。它没有提前阅读。为什么不先声明类型呢?
intinput=NULL
(在
操作
方法的参数列表中)只是wierd(尽管合法)。可能是
int*input=NULL
int-input=0
?这是在我访问函数时使用的,我决定不将参数传递到“input2”
NULL
定义为0,但当需要将整数变量赋给0时,应该使用
0
而不是
NULL
NULL
应用于指针。在某些平台/编译器中,
NULL
可能有
void*
类型是一个转发声明。当您有两个彼此包含的标题时,这是一个非常有用的特性。