|
-
Nov 11th, 2002, 01:22 PM
#1
Thread Starter
Member
Help! Redefinition Error
I have two classes in my project, both of which use the same header file which contains this struct definition:
struct vertex3D {
float X;
float Y;
float Z;
};
When I try to compile the project I get a 'struct' type redefinition error.
How can I include the above header in both classes without getting this error?
-
Nov 11th, 2002, 02:59 PM
#2
Monday Morning Lunatic
Use #ifndef/#define/#endif for header guarding. Search the forums...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 11th, 2002, 05:16 PM
#3
Frenzied Member
like this:
Code:
#ifndef 3DVERTEX
#define 3DVERTEX 1
struct vertex3D {
float X;
float Y;
float Z;
};
/* all the rest of the required stuff here..... */
#endif
It only will be included once this way.
-
Nov 11th, 2002, 08:39 PM
#4
Member
You can use the '#pragma once' preprocessor directive. Put it at the top of your header files. It tells the compiler to only include the header file once.
-
Nov 11th, 2002, 10:37 PM
#5
Junior Member
I really should learn to use those preprocessor macros...
-
Nov 12th, 2002, 06:40 AM
#6
Monday Morning Lunatic
Originally posted by atjs
You can use the '#pragma once' preprocessor directive. Put it at the top of your header files. It tells the compiler to only include the header file once.
That's only for MSVC.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 12th, 2002, 12:16 PM
#7
Originally posted by parksie
That's only for MSVC.
Which is ok if the headers are guaranteed to be only used by MSVC (like headers of MFC apps), but not if the headers contain general utility functions/classes.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|