idmillington / cyclone-physics

The Physics engine that accompanies the book "Game Physics Engine Design"
MIT License
946 stars 265 forks source link

Why dividing core.h and core.cpp? #58

Open awidesky opened 3 years ago

awidesky commented 3 years ago

First, it's more a question from c++ beginner, not a big report or something, not sure if this is acceptable, but please let me give it a shot :)

In core.h, there's almost every definition of class member functions, except for something like Matrix4::getDeterminant or Matrix4::setInverse functions.

I learned "everything in header" approach make member functions implicitly "inline", BUT that "inline" means nothing about optimization, but just a sign that let multiple definition of a member function exist.

So I wish someone could let me know about:

  1. Why put everything in header, so that let compiler compile the same definition in EVERY translation unit that include core.h?
  2. Why Matrix4::getDeterminant andcyclone::getSleepEpsilon, which is short function, in separated in .cpp file, while Matrix4::operator*, which is long function, is in header?