How could C++ compile when there is an undefined function inside source? [closed]
Ok this might be a weird question.. Here's the thing, in the overloaded operator=, I used a clear() helper; But for some reason what I actually implemented was clear(Node *curr) instead of clear(), so there is no function named clear() in the entire source code. However this just compiles fine. My question is why? It didn't even throw me a warning :| Thanks in advance
It could be a compiler error, but what's more likely is that you simply forgot that you implemented such a function or the compiler has found one in a surprising place. If you have an IDE, you can attempt to use tools like Go To Definition and Go To Declaration to attempt to find the definition of the function you called.
I see two possibilities:
your compiler is not linking the operator= method in your app because it is never used, so any missing functions called by it do not matter
if operator= is used and it works, then you made a mistake, there is a clear() method defined. Just verify where the code goes with a source code debugger.
Easy: It found a version of clear() that it can link too.
Just because you don't see it means nothing.
It compiled correctly because:
- There is a header file with a function declaration of clear()
- You are linking against a library with the implementation of the function.
Plain and simple. If it compiled it is there.
精彩评论