(Not logged on) | Register | Log On

You can subscribe to this discussion group using an RSS feed reader. techInterview Discussion

Answers to technical interview questions. A part of TechInterview.org

A part of techInterview.org: answers to technical interview questions.

Your host: Michael Pryor

Multiple inclusion of header file

How can we avoid multiple inclusion of header file.

What are the various ways to solve this problem..
Tez Send private email
Monday, August 07, 2006
 
 
One fairly common way (IME) is to wrap the body of your header file as follows:

#ifndef NAMEOFHEADERFILE_H
#define NAMEOFHEADERFILE_H

// Body of header file ...

#endif // NAMEOFHEADERFILE_H
sibecker
Monday, August 07, 2006
 
 
Another non-portable way is to write

#pragma once

at the top of the header file, which essentially does the same as the previously suggested method.
Josh McFarlane Send private email
Monday, August 07, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz