Preface
I just learned C++ some time ago 防重复声明
, so I wrote it casually, and found that the implementation method kept reporting errors. After searching the Internet for a long time, the problem is not 防重复声明
correct , but I found that it is in the middle. Here is a summary to facilitate the later resolution of the problem.
problem
solve
My header file declaration
#ifdef __PRE_JUDGE__
#define __PRE_JUDGE__
class preJudge
{
public:
int addPreJudge();
int cutPreJudge();
};
#endif // __PRE_JUDGE__
Will be ifndef
written ifdef
, as long as it is modified.
The reason is that work is not careful, the results look a long time, also need to understand ifndef
is if not def
would not have made such a mistake.
It is also the case of preventing duplicate declarations from writing mistakes: sand sculpture demonstration of names other than classes or namespace
Note that the normative writing of anti-duplicate declaration is as follows:
#ifndef 标识符(保证唯一)
#define 标识符(保证唯一)
#endif
other
See other solutions on the Internet, link:
- Write #include "stdafx.h" at the top
- Clean up the cache and regenerate the solution
- The use of #include<iostream> header file library causes conflicts between the name of the class and the namespace, delete #include<iostream> and recompile, and then consider whether to add the header file library again
postscript
Of course, specific issues need specific analysis, but not every detail can be grasped in the process of growing up, so learn more, read more, remember.