# C++: The multiple-declaration problem / Never put using in headers

Yao Yao on March 21, 2015
• Published in category
• C++

## The multiple-declaration problem

The compiler considers the redeclaration of a structure (this includes both structs and classes) to be an error. In fact, both C and C++ allow you to redeclare a function, as long as the two declarations match, but neither will allow the redeclaration of a structure. In C++ this rule is especially important because if the compiler allowed you to redeclare a structure and the two declarations differed, which one would it use?

//: C04:Simple.h
// Simple header that prevents re-definition
#ifndef SIMPLE_H
#define SIMPLE_H
struct Simple {
int i,j,k;
initialize() { i = j = k = 0; }
};
#endif // SIMPLE_H //


## Never put using in headers

You’ll virtually never see a using directive in a header file (at least, not outside of a scope). If you put a using directive (outside of a scope) in a header file, it means that this loss of “namespace protection” will occur with any file that includes this header, which often means other header files. 换言之就是 using 的作用会连锁传播，影响太大。