It appears the answer is no. The MSVC compiler does not have an option equivalent to G++'s -Wmissing-declarations.
Can Visual C++ check for mismatched prototype and implementation?
-
30-09-2022 - |
문제
Can the VC compiler warn if it cannot find an implementation of a prototype?
Example (notice mismatching params):
// calcSomething.h
int calcSomething(
int year,
int month,
int day,
int hour,
int minute,
int second
);
and
// calcSomething.cpp
int calcSomething(
int year,
int month,
int day
)
{
// ... implementation
}
Update: Apparently G++ has a switch called -Wmissing-declarations
which I think might be along the lines of what I need, but obviously for VC++.
해결책
다른 팁
These two are totally different functions, according to the C++ language rules.
The compiler should react in the same way as if the name of the first function was calcSomething
and the name of the second one was calcSomeOtherThing
.
In particular, the function you declared in the header will be undefined, since it has no implementation. Any code which calls it will not compile and link. It is not possible to make an executable which calls a function which was never defined. The compiler doesn't know what to do when the function is called.