Search code examples
c++private

fail to use type in public method


namespace iris {
    namespace imon {
        class myclass {
            private:
                typedef enum ppTag {
                    X1 = 0,
                    X2 = 1,
                    X3 = 254,
                    X4 = 255
                } pp;

                typedef struct {
                    int x;
                    int y;
                    int z;
                } Data;
                pp myFunc();

            public:
                myclass() { };
                virtual ~myclass() {};
                int func();
        };

        pp myclass::myFunc()
        {
         ...
        }

        int myclass::func()
        {
            return 0;
        }
    }
}

g++ returns error: pp does not name a type

I thought I can easily use privately declared structures, typedefs etc. within public methods of the class. What else am I doing wrong?


Solution

  • You need to qualify the type in order to access it:

        myclass::pp myclass::myFunc()
        {
         ...
        }