Skip to content

Pragma once instead of include guards

MiKoronjoo edited this page Nov 21, 2018 · 2 revisions

#pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. Thus, #pragma once serves the same purpose as include guards, but with several advantages, including: less code, avoidance of name clashes, and sometimes improvement in compilation speed.

include guards:

#ifndef STACKOVERFLOW_IN_CPP1_ABSTRACTUSER_H
#define STACKOVERFLOW_IN_CPP1_ABSTRACTUSER_H

class AbstractUser {
.
.
.
};

#endif //STACKOVERFLOW_IN_CPP1_ABSTRACTUSER_H

#pragma once:

#pragma once

class AbstractUser {
.
.
.
};
Clone this wiki locally