Context
I am looking through a large C++ codebase which isn't mine, and I came across this problem
Problem
Suppose we have a class (AClass
) in a header file:
double MethodName(anObject& obj, string s)
and that it is defined in the in the cxx file not as:
double AClass::AMethod(anObject& obj, string s){
as one would expect, but rather as:
double AMethod(anObject& obj, string s){
Without the namespace declaration. This is the only time in the whole cxx file when such a method is defined like this. There are no static declarations on the method, and AClass
does not inherit from any other classes.
Also, I saw how it was called, (in a totally different file, besides AClass.h and AClass.cxx) and the line looks like this:
if(AMethod(obj1, str)>0){
My question is, how does this even compile and run. I would expect this code to falter when compiling
Research
This has been a hard one to search for. Either it is so basic, that it is not directly covered, or there is something complicated going on. If this is a simple straightforward question, please direct me to a topic I can search. I have looked through these:
Putting class declaration in .cpp file
Correct way to define C++ namespace methods in .cpp file
but they were not very pertinent. I have also tried Googling:
"c++ defining a method in cpp file"
"c++ no namespace when defining a method in cpp file"
etc, but to no avail.
NB
if you wish to downvote, I would appreciate it if you were to give a reason, otherwise, I will not learn. Also, if there is any more information, you require, I will do my best to fill you in
Thank You