non-aggregate type error?

Discussion in 'C++' started by Timothee Groleau, Apr 27, 2006.

  1. Hi,

    Could someone tell me what's wrong with this test case based on the compiler
    error I get?

    ==============
    class MyClass
    {
    private:
    int i;
    public:
    void f() {};
    };

    int main()
    {
    MyClass c();
    c.f();
    }

    ==============

    compiler (gcc 3.3.6) output:
    ==============
    test.cpp: In function `int main()':
    test.cpp:12: error: request for member `f' in `c', which is of
    non-aggregate type `MyClass ()()'
    ==============

    Thanks,
    Tim.
    Timothee Groleau, Apr 27, 2006
    #1
    1. Advertising

  2. Timothee Groleau

    Ian Collins Guest

    Timothee Groleau wrote:
    > Hi,
    >
    > Could someone tell me what's wrong with this test case based on the compiler
    > error I get?
    >
    > ==============
    > class MyClass
    > {
    > private:
    > int i;
    > public:
    > void f() {};
    > };
    >
    > int main()
    > {
    > MyClass c();

    MyClass c;

    The compiler thinks your version is a forward declaration of a function.

    --
    Ian Collins.
    Ian Collins, Apr 27, 2006
    #2
    1. Advertising

  3. Ian Collins wrote:

    > The compiler thinks your version is a forward declaration of a function.


    Ha understood, thanks!
    Tim.
    Timothee Groleau, Apr 27, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Vilim

    Re: Non Aggregate Type?

    Ryan Vilim, Aug 2, 2003, in forum: C++
    Replies:
    1
    Views:
    4,373
    Artie Gold
    Aug 2, 2003
  2. Kevin Goodsell

    Re: Non Aggregate Type?

    Kevin Goodsell, Aug 2, 2003, in forum: C++
    Replies:
    1
    Views:
    613
    Kevin Goodsell
    Aug 2, 2003
  3. Christian Christmann

    non-aggregate type bool

    Christian Christmann, Mar 25, 2005, in forum: C++
    Replies:
    3
    Views:
    1,737
    Donovan Rebbechi
    Mar 25, 2005
  4. Alden Pierre
    Replies:
    3
    Views:
    338
    Ben Pope
    Apr 5, 2006
  5. rickman
    Replies:
    5
    Views:
    406
    rickman
    Mar 30, 2013
Loading...

Share This Page