Monday, September 29, 2008

Weekly Code: C++ Include Guards 29/09/2008

Include guards prevents you from including an header file multiple times, it's done by using compiler precessors:

#ifndef FileUtils_H
#define FileUtils_H
#include "FileUtils.h"
#endif

You can also put a #pragma once at the top of the file:

#pragma once

#include "FileUtils.h"

There is also a generator for include guards available.

No comments: