Does g++ compilation order matter?
I noticed that I was 开发者_运维问答able to compile a child class before a parent class with g++. Is there any need to compile in a specific order, with consideration to dependencies?
Linking order can matter; compilation order does not.
In short: No!
Each C++ compilation unit (C++ source file) is compiled independently. Class inheritance etc is set up at runtime. This is why you can have base classes in separately maintained libraries that can be updated without forcing descendant classes to be recompiled, as long as the API and the ABI remains compatible.
In general, no. The compiler will create symbols that represent anything it doesn't recognize but can safely ignore, and the linked will turn those symbols into proper code. In your case the header tells the compiler everything it needs to know to compile your child class, so the specifics can wait.
To expand on ildjarn's answer, compiling a child class's implementation only needs the parent class's API/contract, not its implementation. That would live in a file like Parent.h
which would be included by the file(s) containing the implementation of the child.
...I was able to compile a child class before a parent class...
"Compile" is not a strictly defined term, so it is not exactly clear what you mean here. But in general, no, you can't compile child class before parent class. In C++ parent type must be complete before you'll be able to use as base class for any other child class type. You are either misinterpreted something or giving the term "compile" some rather unorthodox meaning.
精彩评论