Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

psae0001

Problem with VC++ 6.0

This topic is 5247 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I compile the a.cpp in MS VC++ 6.0, I got the following compiling errors: test.h(1) : error C2011: ''_MONEY'' : ''struct'' type redefinition est.h(8) : error C2011: ''TEMP'' : ''struct'' type redefinition Why it happens? Is there anywhere to resolve? It happens when I " typedef enum someEnum {... } myEnum; " as well. What I want is to let both files see the variables MONEY Change & TEMP Change2, so both a.cpp and temp1.cpp can do whatever they need to those variables. Is it possible? ---------------------------------------------------------------- // ************************************************** // // test.h // // ************************************************** typedef struct _MONEY { int Dollars; double Cents; } MONEY; struct TEMP { int Dollars; double Cents; }; // ************************************************** // // temp1.h // // ************************************************** #include <iostream> #include "test.h" using namespace std; extern MONEY Change; // see a.cpp extern TEMP Change2; // see a.cpp void testingf(void); // ************************************************** // // a.cpp // // ************************************************** #include <iostream> #include "test.h" #include "temp1.h" using namespace std; MONEY Change; TEMP Change2; void main() { Change.Cents = 0.02; Change.Dollars = 2; Change2.Cents = 0.04; Change2.Dollars = 4; testingf(); } // ************************************************** // // temp1.cpp // // ************************************************** #include "temp1.h" void testingf(void) { cout << "The change comes out to " << Change.Dollars << " dollars and " << Change.Cents << " cents.\n"; cout << "The change comes out to " << Change2.Dollars << " dollars and " << Change2.Cents << " cents.\n"; }

Share this post


Link to post
Share on other sites
Advertisement
I''m guessing your problem is that your header files lack inclusion guards. Basically temp.h is being pulled into your source file twice. By setting up preprocessor definitions you can stop that. Such as:

//temp.h
#ifndef TEMP_H
#define TEMP_H

// your code here

#endif

You might want to read this article for more information.

Share this post


Link to post
Share on other sites
classic C/C++ mistake, you NEED file inclusion guards in your .h/.hpp files to be able to include them in multiple .c/.cc/.cpp files ... look it up, cause I don''t have time to explain it all again ... it uses #ifndef #define and #endif ... there are many posts explaining it on this site.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!