Subscribe For Free Updates!

We'll not spam mate! We promise.

Apr 14, 2013

How do I put the code of methods outside classes?



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()
{
/* ... */
};

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment