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?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
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.
"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.
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.
Linking order can matter; compilation order does not.
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.