initializing embedded anonymous struct static members?

Discussion in 'C++' started by mark fine, Nov 8, 2004.

  1. mark fine

    mark fine Guest

    ////////////// snippet ////////////////

    struct t {
    static struct { } a;
    };

    struct { } t::a;

    int main(void)
    {
    }

    ////////////// snippet ////////////////

    yields:

    t.cpp:5: conflicting types for `struct {anonymous} t::a'
    t.cpp:2: previous declaration as `struct t::{anonymous} t::a'

    anyway around this? or do i have to stop using anonymous structs and
    declare the trivial embedded structure?

    thanks!

    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
     
    mark fine, Nov 8, 2004
    #1
    1. Advertising

  2. "mark fine" <> wrote in message
    news:p...
    > ////////////// snippet ////////////////
    >
    > struct t {
    > static struct { } a;
    > };
    >
    > struct { } t::a;
    >
    > int main(void)
    > {
    > }
    >
    > ////////////// snippet ////////////////
    >
    > yields:
    >
    > t.cpp:5: conflicting types for `struct {anonymous} t::a'
    > t.cpp:2: previous declaration as `struct t::{anonymous} t::a'
    >
    > anyway around this? or do i have to stop using anonymous structs and
    > declare the trivial embedded structure?


    The following works for me:

    ==============
    struct t {
    typedef struct {} anon;
    static anon a;
    };

    t::anon t::a;

    int main()
    {
    }
    ===============

    -Michael.



    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
     
    Michael Jørgensen, Nov 9, 2004
    #2
    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. JFCM
    Replies:
    4
    Views:
    5,740
  2. Drew McCormack
    Replies:
    2
    Views:
    800
    Drew McCormack
    Jun 24, 2005
  3. Madhav
    Replies:
    14
    Views:
    555
    Howard
    Jul 25, 2006
  4. John
    Replies:
    8
    Views:
    736
    Robbie Hatley
    Jun 2, 2007
  5. richardw

    anonymous struct members

    richardw, Oct 23, 2010, in forum: C Programming
    Replies:
    2
    Views:
    569
    Ben Bacarisse
    Oct 23, 2010
Loading...

Share This Page