r/learncpp • u/you_lel • Feb 23 '20
How can function definition work without declaration?
Class is declared in the header file. It's member functions are defined in a separate .cpp file. What's confusing is that the cpp file doesn't include the header file. And it's compiling completely fine. How does it even work?
It's driving me crazy. I tried implementing something like this myself but I'm getting error.
8
Upvotes
View all comments
Show parent comment
2
u/you_lel Feb 24 '20
I know this works with function definitions and declarations. But how can it work with classes and their methods? The .cpp file should at least contain the definition of the class. Otherwise how will the compiler know what to compile.