Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ classes

Name: scd 2009-01-21 16:54

What benefit does it have, if I write the prototypes of the functions my class will have and then later write the actual functions?

Like for example:

class foo
{
   public:
   int value;
   void getValue();
};

void foo::getValue()
{
  return value;
}


Couldn't I simply define the function inside the class?
Like:

class foo
{
  public:
  int value;
  void getValue()
  {
     return value;
  }
};

Name: Anonymous 2009-01-21 17:03

>>3
If you define the method inside the class, then it's inline, which means that whenever you use the method, the code is copied and inserted into the executable again. This is fine, in fact preferred, for small methods, because it avoids the overhead of truly calling the method, but if you use the method a lot, your executable will bloat.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List