non-aggregate error

Discussion in 'C++' started by Charles Jamieson, Jul 13, 2004.

  1. I am getting an inexplicable compile-time error message. Here is the code

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    #include <string>

    class CBerk
    {
    public:
    CBerk();
    CBerk( std::string ) {}

    char *readUsingKeyword( char *keyword ) {}
    };

    main( int argc, char *argv[] )
    {
    CBerk db(std::string(argv[1]));
    char* record = db.readUsingKeyword(argv[2]);
    }
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    I have extracted the relevant parts of the code. These are the lines
    that produce the error.

    Here is the error message from gcc 3.3.3

    search_test.cpp:15: error: request for member `readUsingKeyword' in
    `db', which
    is of non-aggregate type `CBerk ()(std::string*)'

    I cannot see any problem with this.

    -charles
     
    Charles Jamieson, Jul 13, 2004
    #1
    1. Advertising

  2. "Charles Jamieson" <> wrote in message
    news:FGHIc.77394$XM6.7292@attbi_s53...
    > I am getting an inexplicable compile-time error message. Here is

    the code
    >
    >

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > #include <string>
    >
    > class CBerk
    > {
    > public:
    > CBerk();
    > CBerk( std::string ) {}
    >
    > char *readUsingKeyword( char *keyword ) {}
    > };
    >
    > main( int argc, char *argv[] )
    > {
    > CBerk db(std::string(argv[1]));


    ^^^^^ This is interpretted as a function declaration. So db is not
    of type CBerk.

    > char* record = db.readUsingKeyword(argv[2]);
    > }>

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    >


    Try:

    CBerk db((std::string(argv[1])));

    (((note extra parentheses)))

    Jonathan
     
    Jonathan Turkanis, Jul 13, 2004
    #2
    1. Advertising

  3. Jonathan Turkanis wrote:
    > "Charles Jamieson" <> wrote in message
    > news:FGHIc.77394$XM6.7292@attbi_s53...
    >
    >>I am getting an inexplicable compile-time error message. Here is

    >
    > the code
    >
    >>

    > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    >
    >>#include <string>
    >>
    >>class CBerk
    >>{
    >> public:
    >> CBerk();
    >> CBerk( std::string ) {}
    >>
    >> char *readUsingKeyword( char *keyword ) {}
    >>};
    >>
    >>main( int argc, char *argv[] )
    >>{
    >> CBerk db(std::string(argv[1]));

    >
    >
    > ^^^^^ This is interpretted as a function declaration. So db is not
    > of type CBerk.
    >
    >
    >> char* record = db.readUsingKeyword(argv[2]);
    >>}>

    >
    > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    >
    >
    > Try:
    >
    > CBerk db((std::string(argv[1])));
    >
    > (((note extra parentheses)))
    >
    > Jonathan
    >
    >

    Thanks, you are right. But I still don't understand it. If I replace
    this line with the following two lines:

    std::string name(argv[1]);
    CBerk db(name);

    It compiles with no error. What is the significant difference between
    the two?

    -charles
     
    Charles Jamieson, Jul 13, 2004
    #3
  4. "Charles Jamieson" <> wrote...
    > Jonathan Turkanis wrote:
    > > "Charles Jamieson" <> wrote in message
    > > news:FGHIc.77394$XM6.7292@attbi_s53...
    > >
    > >>I am getting an inexplicable compile-time error message. Here is

    > >
    > > the code
    > >
    > >>

    > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > >
    > >>#include <string>
    > >>
    > >>class CBerk
    > >>{
    > >> public:
    > >> CBerk();
    > >> CBerk( std::string ) {}
    > >>
    > >> char *readUsingKeyword( char *keyword ) {}
    > >>};
    > >>
    > >>main( int argc, char *argv[] )
    > >>{
    > >> CBerk db(std::string(argv[1]));

    > >
    > >
    > > ^^^^^ This is interpretted as a function declaration. So db is not
    > > of type CBerk.
    > >
    > >
    > >> char* record = db.readUsingKeyword(argv[2]);
    > >>}>

    > >
    > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > >
    > >
    > > Try:
    > >
    > > CBerk db((std::string(argv[1])));
    > >
    > > (((note extra parentheses)))
    > >
    > > Jonathan
    > >
    > >

    > Thanks, you are right. But I still don't understand it. If I replace
    > this line with the following two lines:
    >
    > std::string name(argv[1]);
    > CBerk db(name);
    >
    > It compiles with no error. What is the significant difference between
    > the two?


    std::string(whatever)

    is a declaration. The optional parentheses around the parameter name
    preceded by a type-id in a function declaration. Same as

    void foo(int(a));

    Remove the parentheses and you will have

    void foo(int a);

    (less mystery, ain't it?) So, in your declaration it's the same as

    void deebee(int(a[2]));

    or

    void deebee(int a[2]);

    which is the same as

    void deebee(int a[]);

    or

    void deebee(int *a);

    Do you recognize it as a function declaration now? Replace 'void'
    with 'CBerk', 'deebee' with 'db', 'int' with 'std::string'. Nothing
    changes from semantic point of view.

    For the definitiveness' sake the preference was given to declarations.
    If anything _can_ be interpreted as a declaration, it will.

    Victor
     
    Victor Bazarov, Jul 13, 2004
    #4
  5. Victor Bazarov wrote:
    > "Charles Jamieson" <> wrote...
    >
    >>Jonathan Turkanis wrote:
    >>
    >>>"Charles Jamieson" <> wrote in message
    >>>news:FGHIc.77394$XM6.7292@attbi_s53...
    >>>
    >>>
    >>>>I am getting an inexplicable compile-time error message. Here is
    >>>
    >>>the code
    >>>
    >>>
    >>>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    >>>
    >>>
    >>>>#include <string>
    >>>>
    >>>>class CBerk
    >>>>{
    >>>> public:
    >>>> CBerk();
    >>>> CBerk( std::string ) {}
    >>>>
    >>>> char *readUsingKeyword( char *keyword ) {}
    >>>>};
    >>>>
    >>>>main( int argc, char *argv[] )
    >>>>{
    >>>> CBerk db(std::string(argv[1]));
    >>>
    >>>
    >>> ^^^^^ This is interpretted as a function declaration. So db is not
    >>>of type CBerk.
    >>>
    >>>
    >>>
    >>>> char* record = db.readUsingKeyword(argv[2]);
    >>>>}>
    >>>
    >>>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    >>>
    >>>
    >>>Try:
    >>>
    >>> CBerk db((std::string(argv[1])));
    >>>
    >>>(((note extra parentheses)))
    >>>
    >>>Jonathan
    >>>
    >>>

    >>
    >>Thanks, you are right. But I still don't understand it. If I replace
    >>this line with the following two lines:
    >>
    >>std::string name(argv[1]);
    >>CBerk db(name);
    >>
    >>It compiles with no error. What is the significant difference between
    >>the two?

    >
    >
    > std::string(whatever)
    >
    > is a declaration. The optional parentheses around the parameter name
    > preceded by a type-id in a function declaration. Same as
    >
    > void foo(int(a));
    >
    > Remove the parentheses and you will have
    >
    > void foo(int a);
    >
    > (less mystery, ain't it?) So, in your declaration it's the same as
    >
    > void deebee(int(a[2]));
    >
    > or
    >
    > void deebee(int a[2]);
    >
    > which is the same as
    >
    > void deebee(int a[]);
    >
    > or
    >
    > void deebee(int *a);
    >
    > Do you recognize it as a function declaration now? Replace 'void'
    > with 'CBerk', 'deebee' with 'db', 'int' with 'std::string'. Nothing
    > changes from semantic point of view.
    >
    > For the definitiveness' sake the preference was given to declarations.
    > If anything _can_ be interpreted as a declaration, it will.
    >
    > Victor
    >
    >


    Thanks for the explanation. It makes sense now.

    -charles
     
    Charles Jamieson, Jul 13, 2004
    #5
  6. Charles Jamieson

    Anil Mamede Guest


    > Thanks, you are right. But I still don't understand it. If I replace
    > this line with the following two lines:
    >
    > std::string name(argv[1]);
    > CBerk db(name);
    >
    > It compiles with no error. What is the significant difference between
    > the two?
    >
    > -charles
    >


    name is a variable instead of a type.

    Anil Mamede
     
    Anil Mamede, Jul 14, 2004
    #6
  7. Charles Jamieson

    Old Wolf Guest

    Charles Jamieson <> wrote:
    >
    > #include <string>
    >
    > class CBerk
    > {
    > public:
    > CBerk();
    > CBerk( std::string ) {}
    >
    > char *readUsingKeyword( char *keyword ) {}
    > };
    >
    > main( int argc, char *argv[] )
    > {
    > CBerk db(std::string(argv[1]));
    > char* record = db.readUsingKeyword(argv[2]);
    > }


    std::string can be constructed from (char *), so you could avoid the
    issue with:
    CBerk db(argv[1]);
     
    Old Wolf, Jul 14, 2004
    #7
    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,409
    Artie Gold
    Aug 2, 2003
  2. koperenkogel
    Replies:
    3
    Views:
    2,707
    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
    Mar 24, 2005
  3. Alden Pierre
    Replies:
    3
    Views:
    351
    Ben Pope
    Apr 5, 2006
  4. Timothee Groleau

    non-aggregate type error?

    Timothee Groleau, Apr 27, 2006, in forum: C++
    Replies:
    2
    Views:
    714
    Timothee Groleau
    Apr 27, 2006
  5. rickman
    Replies:
    5
    Views:
    430
    rickman
    Mar 30, 2013
Loading...

Share This Page