[C++] Inclusion Guard

There are some useful techniques you can use without headaches. Actually, inclusion guard technique gets rid of annoying header reference problems with just a couple of lines.


1. Inclusion Guards

Large-scaled Production C++ applications tend to use lots of header files. Header files also include other header files. Therefore, it is common that one header file is included multiple times in the same compilation. This multiple inclusion causes multiple definition errors.

For this reason, C++ header files always use a preprocessor coding technique to prevent the content of the header file from appearing more than once.

#ifndef HEADER1_H
#define HEADER1_H

// actual header content


The preprocessor symbol should be unique.


2. Pragma Directive

If you areĀ useing VS C++, you can use the “pragma” directive.

#pragma once

// actual header content

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s