initializing embedded anonymous struct static members?

M

mark fine

////////////// 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!
 
M

Michael Jørgensen

mark fine said:
////////////// 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top