this post was submitted on 22 Mar 2024
230 points (94.2% liked)

Programmer Humor

32588 readers
955 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 41 points 8 months ago* (last edited 8 months ago) (18 children)

Why are you putting the implementation in the .h file? You're supposed to declare in the header and implement in the .cpp files. The meme is reversed

[–] [email protected] -3 points 8 months ago (8 children)

The reason is that header files are pretty much copy/pasted into your c files when you include them. so the code in them keeps getting recompiled for every c file, which drastically increases overall build times. If you only declare in the header and have one c file implementing the functions you compile them only once.

[–] abrahambelch 4 points 8 months ago* (last edited 8 months ago)

Yeah that's why you're supposed to use header guards... If you don't and include your header in multiple places your program straight up won't compile.

load more comments (7 replies)
load more comments (16 replies)