Josh
Josh

Reputation: 3321

Member functions

I am getting an error at the line "void operation" when I compile, because I havent defined Gate_ptr yet. I thought of exchanging the "Gate_ptr" with just "Gate*" instead in the function def. However, is there a way to maintain my current style?

  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;

Upvotes: 0

Views: 107

Answers (2)

xaero99
xaero99

Reputation: 327

Prefer this order:

 //forward decleration
class Gate;

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

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

Upvotes: 4

Luchian Grigore
Luchian Grigore

Reputation: 258648

Forwared declare, do the typedef, then define the class:

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;
};

Upvotes: 4

Related Questions