| | |
Help: 'error: redefinition'
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Hello there, I have here a problem with the compilation of my program. The compiler tells me that my typedefs are redefined, but I defined it only once. Ok, heres the score, I have here a header file (let's name this as file X) that contains all the typedefs that I need (so that I will be able to reuse it to other files). I have included it to the two files (let's say, file A and file B) that really needs it badly and these two files (file A and B) are included to a file that needs them too (let's call this one as file C). Whenever I compile file C, I get the error of redefinition. Is there something wrong with the way I mess with the files? I'm using gcc thus involving Makefile.
Thanks!
Thanks!
Retreat!!!
you header file need code gards to prevent that, like this
C++ Syntax (Toggle Plain Text)
#ifndef MYHEADER #define MYHEADER // code goes here #endif
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
>You could also use #pragma once but it is compiler dependent and deprecated.
All pragmas (well, most with the coming of C99) are compiler dependent. You should avoid them whenever possible. And if #pragma once is compiler dependent, how can you say that it's deprecated? Have all compilers documented it as deprecated? Anyway, the only real advantage of #pragma once is that you don't have to worry about naming collisions in your inclusion guards, and that's not worth the loss of portability.
All pragmas (well, most with the coming of C99) are compiler dependent. You should avoid them whenever possible. And if #pragma once is compiler dependent, how can you say that it's deprecated? Have all compilers documented it as deprecated? Anyway, the only real advantage of #pragma once is that you don't have to worry about naming collisions in your inclusion guards, and that's not worth the loss of portability.
I'm here to prove you wrong.
•
•
•
•
>You could also use #pragma once but it is compiler dependent and deprecated.
All pragmas (well, most with the coming of C99) are compiler dependent. You should avoid them whenever possible. And if #pragma once is compiler dependent, how can you say that it's deprecated? Have all compilers documented it as deprecated? Anyway, the only real advantage of #pragma once is that you don't have to worry about naming collisions in your inclusion guards, and that's not worth the loss of portability.
Didn't this worked as suggested by Ancient Dragon . Its better to use that and you must know how to use it
c Syntax (Toggle Plain Text)
#ifndef MYHEADER #define MYHEADER // code goes here #endif
Last edited by vishesh; Sep 13th, 2007 at 6:17 am.
![]() |
Similar Threads
- Porting from Sun C++ compiler to GNU gcc (C++)
- Error LNK2005 (C++)
- SQLCA Error (Oracle)
- please tell me wht's GOTO (C)
- Cant compile on Linux (IT Professionals' Lounge)
- Please point me in the right way for the ending of my C program. (C)
- Doubts about constructor (C++)
- Playing cards (C++)
Other Threads in the C++ Forum
- Previous Thread: decimal to binary conversion
- Next Thread: project
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






