How do I put the code of methods outside classes?
It is possible to put in a class only the prototype of the methods, and to put all the
algorithms outside. This is recommended, because it allows the programmer to read
a short prototype of the class, and makes re-usability easier:
// in a header file (.h file)
struct A
{
int a;
A();
virtual ~A();
void f();
};
// in a compilation unit (.cpp file)
A::A()
{
/* ... */
};
A::~A()
{
/* ... */
};
void A::f()
{
/* ... */
};
0 comments:
Post a Comment