Translation unit when including a source file?

139 Views Asked by At

As far as I know, a translation unit consists of a single implementation file .cpp/.c and all its included headers' code. When including a .cpp file inside another .cpp file, or including a .cpp file inside a .h file that is included inside yet another .cpp file, what is the translation units we have here?

1

There are 1 best solutions below

2
Employed Russian On BEST ANSWER

When including a .cpp file inside another .cpp file, or including a .cpp file inside a .h file that is included inside yet another .cpp file, what is the translation units we have here?

A translation unit is a single file that is being compiled. Here it's the "outernmost" .cpp file.

That said, #including a .cpp inside .h is a really bad idea™️.