Hello,
I was taught that when declaring a class you put the
code in one file (.h) and the methods implementations in
another file (.cpp). I noticed that the author has placed
both class declaration and methods in one file. Going by
what I have been taught, I am splitting these up in
different files, for example
class IPacket
{
// Code here
};
and save in the file called "IPacket.h". Now I will write the implementation,
#include "IPacket.h"
class BinaryPacket : public IPacket
{
inline BinaryPacket(char const * const data, u_long size);
// More Code here&
};
Save the file in "BinPacket.h".
#include "BinPacket.h"
inline BinaryPacket::BinaryPacket(char const * const data, u_long size)
{
// Code here.
}
and save this file in BinPack.cpp. I keep doing this for all
classes and implementations, but I end up with errors
when compiling. I am assuming that when compiling, it
will read all the includes files and compile it as if it were in
one big file, right?
Also, this brings me to another question, is it 'standard
practice' to write the class AND the methods in one file,
or split them up as I am trying to do? I understand that
you will have tons (as if files have mass and can be
weighed) of files, but is it better?
Thank you
S.
I was taught that when declaring a class you put the
code in one file (.h) and the methods implementations in
another file (.cpp). I noticed that the author has placed
both class declaration and methods in one file. Going by
what I have been taught, I am splitting these up in
different files, for example
class IPacket
{
// Code here
};
and save in the file called "IPacket.h". Now I will write the implementation,
#include "IPacket.h"
class BinaryPacket : public IPacket
{
inline BinaryPacket(char const * const data, u_long size);
// More Code here&
};
Save the file in "BinPacket.h".
#include "BinPacket.h"
inline BinaryPacket::BinaryPacket(char const * const data, u_long size)
{
// Code here.
}
and save this file in BinPack.cpp. I keep doing this for all
classes and implementations, but I end up with errors
when compiling. I am assuming that when compiling, it
will read all the includes files and compile it as if it were in
one big file, right?
Also, this brings me to another question, is it 'standard
practice' to write the class AND the methods in one file,
or split them up as I am trying to do? I understand that
you will have tons (as if files have mass and can be
weighed) of files, but is it better?
Thank you
S.
The post was edited 2 times, last by Sabrina ().