whats wrong with this ? (compilation errors)

Discussion in 'C++' started by 2b|!2b==?, Apr 7, 2007.

  1. 2b|!2b==?

    2b|!2b==? Guest

    typedef struct llist_entry_s llist_entry; /* opaque type */

    struct llist_entry_s
    {
    llist_entry * next;
    char * keyword;
    char * value;

    llist_entry() :next(0), keyword(0), value(0)
    {
    }
    };
     
    2b|!2b==?, Apr 7, 2007
    #1
    1. Advertising

  2. 2b|!2b==?

    jalina Guest

    2b|!2b==? a écrit :
    > typedef struct llist_entry_s llist_entry; /* opaque type */
    >
    > struct llist_entry_s
    > {
    > llist_entry * next;
    > char * keyword;
    > char * value;
    >
    > llist_entry() :next(0), keyword(0), value(0)
    > {
    > }
    > };

    llist_entry() is not a valid member function declaration. Did you mean
    llist_entry_s() ?

    J.
     
    jalina, Apr 7, 2007
    #2
    1. Advertising

  3. 2b|!2b==?

    James Kanze Guest

    On Apr 7, 9:40 pm, "2b|!2b==?" <> wrote:
    > typedef struct llist_entry_s llist_entry; /* opaque type */


    Why the typedef? I'd just write:

    class llist_entry ;

    (My coding standards say to only use the keyword "class" for
    forward declarations.)

    > struct llist_entry_s
    > {
    > llist_entry * next;
    > char * keyword;
    > char * value;


    > llist_entry() :next(0), keyword(0), value(0)


    There are two errors here: first, you didn't specify a return
    type for the function, and second, you try to use an initializer
    sequence which is only legal in constructors.

    > {
    > }
    > };


    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Apr 7, 2007
    #3
  4. 2b|!2b==?

    Mike Wahler Guest

    "2b|!2b==?" <> wrote in message
    news:...
    > typedef struct llist_entry_s llist_entry; /* opaque type */
    >
    > struct llist_entry_s
    > {
    > llist_entry * next;
    > char * keyword;
    > char * value;
    >
    > llist_entry() :next(0), keyword(0), value(0)
    > {
    > }
    > };


    You don't say what compiler errors you get.

    The above code compiles successfully for me with VC++.

    BTW you don't need that typedef. You could write it
    like this:

    struct llist_entry
    {
    llist_entry * next;
    char * keyword;
    char * value;

    llist_entry() :next(0), keyword(0), value(0)
    {
    }
    };

    -Mike
     
    Mike Wahler, Apr 7, 2007
    #4
  5. 2b|!2b==?

    Mike Wahler Guest

    "James Kanze" <> wrote in message
    news:...
    On Apr 7, 9:40 pm, "2b|!2b==?" <> wrote:
    > > typedef struct llist_entry_s llist_entry; /* opaque type */


    > Why the typedef? I'd just write:
    >
    > class llist_entry ;
    >
    > (My coding standards say to only use the keyword "class" for
    > forward declarations.)


    > > struct llist_entry_s
    > > {
    > > llist_entry * next;
    > > char * keyword;
    > > char * value;
    > >
    > > llist_entry() :next(0), keyword(0), value(0)


    > There are two errors here: first, you didn't specify a return
    > type for the function,


    It's a constructor; no return type.

    > and second, you try to use an initializer
    > sequence which is only legal in constructors.


    It is a ctor.

    -Mike

    > > {
    > > }
    > > };
     
    Mike Wahler, Apr 7, 2007
    #5
  6. 2b|!2b==?

    2b|!2b==? Guest

    Mike Wahler wrote:

    > "2b|!2b==?" <> wrote in message
    > news:...
    >
    >>typedef struct llist_entry_s llist_entry; /* opaque type */
    >>
    >>struct llist_entry_s
    >>{
    >> llist_entry * next;
    >> char * keyword;
    >> char * value;
    >>
    >> llist_entry() :next(0), keyword(0), value(0)
    >> {
    >> }
    >>};

    >
    >
    > You don't say what compiler errors you get.
    >
    > The above code compiles successfully for me with VC++.
    >
    > BTW you don't need that typedef. You could write it
    > like this:
    >
    > struct llist_entry
    > {
    > llist_entry * next;
    > char * keyword;
    > char * value;
    >
    > llist_entry() :next(0), keyword(0), value(0)
    > {
    > }
    > };
    >
    > -Mike
    >

    Ah, I'm back now - I needed the break (and some coffee). I sorted this
    one out. It was due to the file extension (*.c) - it was expecting C
    code - so compiler barfed when it got to the initialization list ...
    >
     
    2b|!2b==?, Apr 8, 2007
    #6
  7. 2b|!2b==?

    Heinz Ozwirk Guest

    "Mike Wahler" <> schrieb im Newsbeitrag
    news:fISRh.135322$...
    >
    > "James Kanze" <> wrote in message
    > news:...
    > On Apr 7, 9:40 pm, "2b|!2b==?" <> wrote:
    >> > typedef struct llist_entry_s llist_entry; /* opaque type */

    >
    >> Why the typedef? I'd just write:
    >>
    >> class llist_entry ;
    >>
    >> (My coding standards say to only use the keyword "class" for
    >> forward declarations.)

    >
    >> > struct llist_entry_s
    >> > {
    >> > llist_entry * next;
    >> > char * keyword;
    >> > char * value;
    >> >
    >> > llist_entry() :next(0), keyword(0), value(0)

    >
    >> There are two errors here: first, you didn't specify a return
    >> type for the function,

    >
    > It's a constructor; no return type.


    A constructor is a "function" which has the same name as the class (or
    struct) it belongs to. Here, the name of the struct is "llist_entry_s" and
    the name of the supposed c-tor is "llist_entry". Those names are different
    and therefore llist_entry_s::llist_entry() is not a constructor. It doesn't
    matter that somewhere else there is a typedef for llist_entry. Any names
    declared outside the scope of llist_entry_s may be overwritten by another
    declaration inside that scope.

    Heinz
     
    Heinz Ozwirk, Apr 8, 2007
    #7
  8. 2b|!2b==?

    James Kanze Guest

    On Apr 7, 9:56 pm, "Mike Wahler" <> wrote:
    > "James Kanze" <> wrote in message
    >
    > news:...
    > On Apr 7, 9:40 pm, "2b|!2b==?" <> wrote:


    > > > typedef struct llist_entry_s llist_entry; /* opaque type */

    > > Why the typedef? I'd just write:


    > > class llist_entry ;


    > > (My coding standards say to only use the keyword "class" for
    > > forward declarations.)


    > > > struct llist_entry_s
    > > > {
    > > > llist_entry * next;
    > > > char * keyword;
    > > > char * value;


    > > > llist_entry() :next(0), keyword(0), value(0)

    > > There are two errors here: first, you didn't specify a return
    > > type for the function,


    > It's a constructor; no return type.


    No it's not. A constructor has the same name as the class.
    This is apparently an attempt to declare a member function.

    > > and second, you try to use an initializer
    > > sequence which is only legal in constructors.


    > It is a ctor.


    No it's not. That's why he's having problems.

    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Apr 8, 2007
    #8
  9. 2b|!2b==?

    James Kanze Guest

    On Apr 7, 9:54 pm, "Mike Wahler" <> wrote:
    > "2b|!2b==?" <> wrote in message


    > news:...


    > > typedef struct llist_entry_s llist_entry; /* opaque type */


    > > struct llist_entry_s
    > > {
    > > llist_entry * next;
    > > char * keyword;
    > > char * value;


    > > llist_entry() :next(0), keyword(0), value(0)
    > > {
    > > }
    > > };


    > You don't say what compiler errors you get.


    > The above code compiles successfully for me with VC++.


    It shouldn't. G++ says:
    ctor.cc:16: error: ISO C++ forbids declaration of 'llist_entry'
    with no type
    ctor.cc:18: error: declaration of 'int
    llist_entry_s::llist_entry()'
    ctor.cc:8: error: changes meaning of 'llist_entry' from 'typedef
    struct llist_entry_s llist_entry'
    ctor.cc: In member function 'int llist_entry_s::llist_entry()':
    ctor.cc:16: error: only constructors take base initializers
    Which is what I'd expect.

    > BTW you don't need that typedef. You could write it
    > like this:


    > struct llist_entry
    > {
    > llist_entry * next;
    > char * keyword;
    > char * value;


    > llist_entry() :next(0), keyword(0), value(0)
    > {
    > }
    > };


    That would be more idiomatic C++, of course.

    --
    James Kanze (Gabi Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Apr 8, 2007
    #9
    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. Alexandre Martins

    Whats wrong with this provider ??

    Alexandre Martins, Aug 14, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    366
    Guenther Liebowitz
    Aug 14, 2003
  2. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,009
    Mark Goldin
    Jan 17, 2004
  3. aa

    Whats wrong with numbers

    aa, Feb 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    313
    Patrice Scribe
    Feb 6, 2004
  4. sviau

    whats wrong with this header???

    sviau, Feb 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    588
    mikeb
    Feb 6, 2004
  5. aa

    Whats wrong

    aa, May 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,585
    Kevin Spencer
    May 20, 2004
Loading...

Share This Page