?
Solved

Renaming classes, handling header guard GUIDs

Posted on 2004-09-02
2
Medium Priority
?
277 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 120 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 80 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

830 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