SoFunction
Updated on 2025-04-05

Unable to match function definitions with existing declarations Solution to the problem Share

Tonight, I encountered the following problems.

d:\My Document\visual studio 2008\projects\virtualosc\(171): error C2244:
"arrayListType<elemType>::maxListSize": Unable to match function definition with existing declaration
1> d:\My Document\visual studio 2008\projects\virtualosc\(37): See
Statement of "arrayListType<elemType>::maxListSize"
1> Definition
1> 'int arrayListType::maxListSize(void)'
1> Existing Statement
1> 'int arrayListType<elemType>::maxListSize(void)'

I thought about it for a long time but couldn't solve it. Later, with the help of Baidu, I solved it. The problem is actually easy to solve, but I didn’t expect it, but I didn’t expect it. Now record the problem and you can quickly solve it if it occurs again next time. The solution is as follows:

Joined before:

#ifndef ARRAYLISTTYPE_H
#define ARRAYLISTTYPE_H

Add at the end:

#endif

In this way, the header file will not be included repeatedly, resulting in compilation errors. Now, explain the above statement.


#ifndef ARRAYLISTTYPE_H means "If no macro is defined ARRAYLISTTYPE_H"

#define ARRAYLISTTYPE_H means "Define macro ARRAYLISTTYPE_H"

#endif means "end"

In general, if the identifier ARRAYLISTTYPE_H is not defined, then define the identifier ARRAYLISTTYPE_H and let the code between #ifndef and #endif be compiled and processed. If the header file ARRAYLISTTYPE_H is included for the second time, the statement #ifndef will be invalid, and all statements before #endif will be ignored by the compiler. ———Data Structure Using C++,

In the future, remember to add the above preprocessing commands if you write the header file yourself.