There are many references to the compilation / binding process, but I am interested in a more specific problem: compiling a class.
The question is, because in general you need to know things before you can use them. For example: you cannot call a function if it has not been previously declared.
In classes, this is not the case. You can use the item until it appears. What does the compiler do? Does the standard say anything about the previous compilation step?
To be more specific, the following example shows how we can use the elements defined below.
#include <iostream> class EvenOdd { public: EvenOdd(): value(0) {} void assignEven(unsigned v) { if (v>0 && v%2==1) { std::cout << "Wrong call... is odd" << std::endl; assignOdd(v); } else { std::cout << "Right..." << v << " is Even" << std::endl; value= v; } } void assignOdd(unsigned v) { if (v>0 && v%2==0) { std::cout << "Wrong call... is even" << std::endl; assignEven(v); } else { std::cout << "Right..." << v << " is Odd" << std::endl; value= v; } } private: unsigned value; }; int main() { EvenOdd a; std::cout << "Do it right..." << std::endl; a.assignEven(2); std::cout << "doing it wrong..." << std::endl; a.assignEven(3); }
We could also add additional questions about the built-in functions that can be defined after the dial-peer, and the compiler can solve without problems. I think the answer is related.
UPDATE: I know that compiling / linking has several steps. On the other hand, if the compiler accepts a call to the function defined below because the compiler has parsed the code in a way. The question is which of the previous steps has already been done? Also ... in what part of the standard do we find something related to using the member defined below?
Knowing how the compiler works is very interesting because it needs to know the details of the function below (at least the header), which seems to be true for compilation. Even the data item must be compiled because you need to bind its type in the context of the function above
It works as if the code is reordered, but it is not consistent with the above example, because both members of the function call each other. This is similar to reordering data items, and the function header may be code that is considered by the compiler.
source share