0

I'm using the directive pragma once in two header files. Both headers use vector, iterator, iostream, and string (and using namespace std). Some things may seem redundant and inefficient but it's the way our instructor wants us to write it. Anyways, in my file register.cpp, I want to include both header files. Would I attach pragma once here as well?

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Narue
0

>Would I attach pragma once here as well?
I don't see why you would need to unless you actually include register.cpp in another file. Otherwise, it'll work without the #pragma because implementation files must only have one instance in the translation unit or you'll get multiple definition errors. #pragma once is a non-portable equivalent for inclusion guards in headers, nothing more (barring compilation optimizations). If #pragma once is supported then:

#ifndef UNIQUE_NAME
#define UNIQUE_NAME

// Header shtuff

#endif

Is (probably) functionally identical to:

#pragma once

// Header shtuff
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.