Thank you. If I include it inline, I would not need to have a .cpp file then. Is that right? Is it ok not to have a .cpp on some occasions like this one?
---------- Post updated at 05:02 AM ---------- Previous update was at 04:45 AM ----------
I had originally some code concerning a class (definition and implementation) in a header file put have now split it to have the definition and inline functions in the .h file, and the rest of the implementation in a .ccp file.
This is what I have for the .cpp file
The #ifndef, #define, #include and #endif were in the .h file. Should I remove them from the .cpp file as well, as to your explanation?
#ifndef COMPLEX_H
#define COMPLEX_H
#include <assert.h>
#include <cmath>
#include <iostream>
#include "gendef.h"
//////////////////////////////////////////////////////////////////////////
Complex& Complex:operator /= (const Complex& C) {
assert((C.Re != 0) || (C.Im != 0));
REAL mod = (C.Re * C.Re) + (C.Im * C.Im);
REAL nr, ni;
nr = ( (Re * C.Re) + (Im * C.Im) ) / mod;
ni = ( (C.Re * Im) - (Re * C.Im) ) / mod;
Re = nr;
Im = ni;
return (*this);
}
#endif
Those #ifndef/#define/#endif don't belong there, no. That arrangement is to prevent a .h file from being included more than once -- if you accidentally do so, FILE_H will already be defined and the preprocessor will harmlessly skip over the contents.
The string is completely arbitrary, by the way. You could have #ifndef SLARTIBARTFAST and it would work, as long as SLARTIBARTFAST is only used for one .h file.