Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@nitwhiz
If you want to do one class per file, then I think yes.
Most games should be written in CPP, or at least their engine. -
Hazarth94765yYes, you should have a header for every c/cpp file. You can write code directly into .h files and it will work from a single file (and I do write some smaller helper classes or libs like that sometimes) but its cleaner to split it up, you can even have a single header and multiple .cpp files implementing different parts of it. The headers are mostly supposed to provide forward declarations for everything you write. Much like in for example python, you can't use functions or variables that weren't previously declared. The headers are ordered by priority and pasted to the resulting code at the top so all things are declared, then you can provide a definition anywhere else in the code and C will find it. This also means that you need to be careful about cyclic dependencies. If A needs B to be declared and B needs A, the compiler will no longer be able to place them correctly and compilation will fail.
-
Hazarth94765y@netikras no, headers are just declarations of your code. You cant provide two implementations for the same function in single header. That would be like writting this in java:
public String hello(){
return "hello";
}
public String hello(){
return "goodbye";
}
It wouldnt compile because you have ambiguous method signature. Thats what a header provides, signatures for classes, variables, functions... You just should to write their concrete definitions in the .c file
An interface gives your code a "model" of what *any* implementation has to provide. a header tells your compiler "function/class/variable with thisName(int) exists somewhere in this codebase"
I can see why you'd think its similar, but it works in two very different context and towards two very different goals. -
To answer your last question: every UE game, every game using the CryEngine, a lot of EA games (including battlefield and need for speed), and a whole lot of indie games
Related Rants
-
xjose97x19Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
-
Cyborg15A guy and a girl are in a Java seminar. Afterward, the guy approaches the girl and asks, "Hey gurrl, can I ge...
-
Unskipp24So this happened last night... Gf: my favorite bra is not fitting me anymore Me: get a new one ? Gf: but it ...
How do you do java style oop with classes and inheritance and all that in c++?
Do I really have to make a header and a source file for each class?
And while we are on it: are there any sources of "famous" games written in cpp?
question
oop
makefile
headers
c++
style