Sign in to follow this  

Small function's implementations in headers

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this