error: ISO C++ forbids declaration of 'm' with no type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brucedd
    New Member
    • Mar 2008
    • 2

    error: ISO C++ forbids declaration of 'm' with no type

    I suspect I don't understand namespaces or something, but does anyone have an idea of why the following code segment which is all in a single *.h file causes a compile error?

    namespace first {
    typedef class _A {
    public:
    _A() {};
    ~_A() {};
    void set(int c) {b = c;};
    int b;
    } A;
    } //end namespace first

    namespace first {
    namespace second {
    namespace third {
    class foo {
    public:
    foo() {};
    ~foo() {};
    int c;
    A m;
    m.set(c);
    };
    } // end third
    } //end second
    } // end first

    Any help or debug ideas appreciated. Thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Several things look funny but this is an error:

    Originally posted by brucedd
    m.set(c);
    That is a function call inside a class definition. You can't do that.

    Comment

    • brucedd
      New Member
      • Mar 2008
      • 2

      #3
      Oh, of course you are right about that. I'll need to find another way to do this because when I originally tried writing the class _A so the constructor took an int as an argument the compiler didn't like that either:

      class foo {
      foo() {};
      ~foo() {};

      A m(c);

      }

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Really?

        [code=cpp]
        class _A
        {
        public:
        _A(int);
        };
        [/code]

        but that requires:
        [code=cpp]
        class foo
        {
        public:
        foo(int arg) : m(arg){};
        ~foo() {};
        private:
        A m;
        };
        [/code]

        Did you try this?

        Comment

        Working...