Solved

Renaming classes, handling header guard GUIDs

Posted on 2004-09-02
2
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

717 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