Solved

Renaming classes, handling header guard GUIDs

Posted on 2004-09-02
2
262 Views
Last Modified: 2012-05-05
When I create a new class in VC++ 6.0, an MFC class for example, Visual Studio will generate a header and implementation file, and within that header is a header guard, something along the lines of

#IFDEF  __MYCLASSNAME_H_GUID

Anyway - say I want to later rename the class, either before or after it is actually in use elsewhere in the codebase. I would first change the names of the .H and .CPP files, and change all instances of CMyClassName throughout the code to CMyNewName as well as all include references etc. What, if anything do I have to do to the header guard, specifically, the GUID portion of it? Is that value installed in the registry or anything and further used by the compiler, or is purely a long random number used only to insure a unique identifier?

thanks
-Paul
0
Comment
Question by:PMH4514
2 Comments
 
LVL 3

Accepted Solution

by:
teratoma earned 30 total points
ID: 11970339
Rest assured, the header guard is only there to prevent the header from being included twice in the same compilation unit.  This is the basic C workaround to the multiple inclusion problem.  Changing the filename or the name of the class will not cause a problem unless __MYCLASSNAME_H_GUID somehow gets defined elsewhere.  The only true guideline is that each header has a unique guard.  Well, underscores in front are discouraged, but that was MS's decision not yours :)
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 20 total points
ID: 11971165
It's good practice to use the filename as guard. e. g. header.h  gives

#ifdef HEADER_H
#define HEADER_H

#endif // HEADER_H

That GUID thing of MFC wizard is some kind of stupidity i always remove from my projects. It's the same as you would use a loop counter variables having a 40 character long name.

Regards, Alex

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 67
C++ Language error 28 214
How to convert MFC APP to Win32 APP. 19 79
Problem with SqlConnection 4 168
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now