Can't typedef a struct

D

desktop

I have this in a .h file which I include in a .cpp file:

typedef struct {
double x;
double y;
} pointz;

But when I compile I get:

graphics/debug.h:13: error: conflicting declaration ‘typedef struct
pointz pointz’
graphics/debug.h:13: error: ‘pointz’ has a previous declaration as
‘typedef struct pointz pointz’

But I have not previously declared 'points'.
 
I

Ian Collins

desktop said:
I have this in a .h file which I include in a .cpp file:

typedef struct {
double x;
double y;
} pointz;
In C++, don't use typedef.

struct pointz
{
double x;
double y;
};
 
J

Jim Langston

Ian Collins said:
In C++, don't use typedef.

struct pointz
{
double x;
double y;
};

In addition, it may be you are tying to include this twice without include
guards.
 
D

desktop

Ian said:
In C++, don't use typedef.

struct pointz
{
double x;
double y;
};

with

struct pointz {
double x;
double y;
};

Then I just get:


graphics/debug.h:10: error: redefinition of ‘struct pointz’
graphics/debug.h:10: error: previous definition of ‘struct pointz’

even though its not been declared before.
 
I

Ian Collins

desktop said:
with

struct pointz {
double x;
double y;
};

Then I just get:


graphics/debug.h:10: error: redefinition of ‘struct pointz’
graphics/debug.h:10: error: previous definition of ‘struct pointz’

even though its not been declared before.

Then you have done what Jim speculated and included a header without
include guards twice.
 
J

Jim Langston

desktop said:
with

struct pointz {
double x;
double y;
};

Then I just get:


graphics/debug.h:10: error: redefinition of ‘struct pointz’
graphics/debug.h:10: error: previous definition of ‘struct pointz’

even though its not been declared before.

Try this.

#ifndef POINTZ_DEF
#define POINTZ_DEF

struct pointz {
double x;
double y;
};

#endif

If that works, that means you are including the header twice without include
guards. Whcih are somethign like this:

myheader.h:
#ifndef MYHEADER_H
#define MYHEADER_H

// header goes here

#endif
 
K

karthikbalaguru

with

struct pointz {
double x;
double y;

};

Then I just get:

graphics/debug.h:10: error: redefinition of 'struct pointz'
graphics/debug.h:10: error: previous definition of 'struct pointz'

even though its not been declared before.- Hide quoted text -

- Show quoted text -

Possibly a Header problem :(

Karthik Balaguru
 
J

Juha Nieminen

desktop said:
I have this in a .h file which I include in a .cpp file:

In a .cpp or in at least another .h file and the .cpp file?

You probably need multiple inclusion guards.
 
B

BobR

Jim Langston wrote in message...
If that works, that means you are including the header twice without include
guards. Whcih are somethign like this:

myheader.h:
#ifndef MYHEADER_H
#define MYHEADER_H

// header goes here

#endif

Add:

Do yourself a BIG favor and comment all #endif.

#endif // #ifndef MYHEADER_H

When you get to the bottom of a file and see 20 or 30 #endif, it is hard to
know which is ending what.

My GCC(MinGW) system headers all have the comments, and it really helps when
reading them (understanding them is a whole other thing! <G>).
 
R

R Samuel Klatchko

desktop said:
graphics/debug.h:10: error: redefinition of ‘struct pointz’
graphics/debug.h:10: error: previous definition of ‘struct pointz’

even though its not been declared before.

Notice that the error lines say the previous definition is the same
file:line as the redefinition. This means the file graphics/debug.h is
being included multiple times.

As other people on this thread have noted, you should use inclusion
guards to prevent multiple includes from causing definitions to be seen
twice.

samuel
 
S

Stefan Naewe

Jim Langston wrote in message...

Add:

Do yourself a BIG favor and comment all #endif.

#endif // #ifndef MYHEADER_H

When you get to the bottom of a file and see 20 or 30 #endif, it is hard to
know which is ending what.

Why would you have that many #endif's at the bottom of a file ?

My GCC(MinGW) system headers all have the comments, and it really helps when
reading them (understanding them is a whole other thing! <G>).


Regards,
Stefan
 
J

James Kanze

Jim Langston wrote in message...

Do yourself a BIG favor and comment all #endif.
#endif // #ifndef MYHEADER_H

Why bother? There should only be one. Other than as include
guards, conditional compilation is really something to be
avoided.
When you get to the bottom of a file and see 20 or 30 #endif,
it is hard to know which is ending what.

If you get to the bottom of a file, and see 20 or 30 #endif,
it's easy to know that the system should be reengineered.
 
B

BobR

Stefan Naewe wrote in message...
Why would you have that many #endif's at the bottom of a file ?

I do NOT! But, I've seen it.

And I agree with you, James and Ian.
 

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,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top