Solved

Renaming classes, handling header guard GUIDs

Posted on 2004-09-02
2
259 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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

728 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

10 Experts available now in Live!

Get 1:1 Help Now