mardi 29 mars 2016

Should my C++ inline methods be explicitly declared as inline?

(I'm using gnu g++ v5.2.1 and C++11, but this is a generic C++ question.)

I'd like to put a few trivial methods in my .hpp files. Many .cpp files in my project include this .hpp file:

class foo
{
    public:

        int        example1( int i ) { return i + 5; }
        inline int example2( int i ) { return i + 5; }
};

Is there a difference between example1() and example2() when one is explicitly declared inline and the other one doesn't mention inline?

Should I prefer one over the other?

Aucun commentaire:

Enregistrer un commentaire