Jump to content
  • Advertisement
Sign in to follow this  
Coz

Small function's implementations in headers

This topic is 4481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Recently I have been working with some code which basicly has all the short functions(1 or 2 lines) implementation right in the header instead of just the declaration of the function. Is this a good idea? It might help people find small functions easier than in a huge file... For example:
//file foo.h
struct foo
{
   int a;

   void long_func();
 
   int do_it(int val){a = val; return a;}//Wise or stupid?
   foo(){a = 0;}//Same question
};

//file foo.cpp
#include "foo.h"

void foo::long_func()
{
//Do a bunch of stuff here
}

Share this post


Link to post
Share on other sites
Advertisement
Defining member functions in the class declaration will implicitly declare them inline. And yes it can help readability in some cases.

Share this post


Link to post
Share on other sites
Quote:
Original post by Baraclese
Defining member functions in the class declaration will implicitly declare them inline. And yes it can help readability in some cases.


More speciffically, if you are implementing a property-like interface with get_ and set_ functions I would find it easier to read it in the .h file then the .cpp file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!