Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use #include in big projects?

Tags:

c++

include

Should I #include everything I need in every header/cpp file? I am working on a 2d game engine atm (for practice mostly) and in reviewing my code I realise that I repeat string and vector in almost every file. Is this an issue and how do I deal with it?

I've always had the opinion that every class or module you write should stand on it's own two legs, so to speak. I really enjoy generic programming (I'm including my own script language in the engine, with my own drafted script engine) but I also realise it could cause a lot of overhead and confusion.

like image 230
Sebastian Zander Avatar asked Jul 01 '12 01:07

Sebastian Zander


People also ask

When should a semicolon be used examples?

When you have a conjunctive adverb linking two independent clauses, you should use a semicolon. Some common conjunctive adverbs include moreover, nevertheless, however, otherwise, therefore, then, finally, likewise, and consequently. I needed to go for a walk and get some fresh air; also, I needed to buy milk.

How do you use a semicolon in a sentence?

Use a semicolon to join two related independent clauses in place of a comma and a coordinating conjunction (and, but, or, nor, for, so, yet). Make sure when you use the semicolon that the connection between the two independent clauses is clear without the coordinating conjunction.

Where do you use a colon and semicolon?

Colons introduce or define something. The primary use of semicolons is to join two main clauses. The difference between semicolons and colons is that colons can combine two independent clauses, but their primary use is to join independent clauses with a list or a noun.


1 Answers

I would stick to including <string> and <vector> only where necessary.

As for making sure individual header files stand on their own, I like how the Google C++ Style Guide deals with include order. Basically, always list the corresponding foo.hpp include before all other includes in foo.cpp. That way, we know that foo.hpp won't expect something to be included before it and fail if it isn't there.

like image 142
robert Avatar answered Oct 07 '22 20:10

robert