C++ – How to implement static class member functions in *.cpp file

c++

Is it possible to implement static class member functions in *.cpp file instead of doing
it in the header file ?

Are all static functions always inline?

Best Solution

It is.

test.hpp:

class A {
public:
    static int a(int i);
};

test.cpp:

#include <iostream>
#include "test.hpp"


int A::a(int i) {
    return i + 2;
}

using namespace std;
int main() {
    cout << A::a(4) << endl;
}

They're not always inline, no, but the compiler can make them.