Below is some simplified code from a header file in which the free functions are declared but not defined and the vector is both declared and defined.
The cpp file contains the implementation of the free functions.
I was wondering if there was a way to declare the vector in the header file and put the definition in the cpp file.
// my-file.h
namespace MyNamespace
{
bool foo(const std::string& name, const std::string& value);
void bar(const std::string& name, const std::string& value);
const std::vector<std::function<void(const std::string&, const std::string&)>> m_myVector
{
foo,
bar,
[](const std::string& name, const std::string& value)
{
// do some stuff
}
};
} // MyNamespace
You may declare const variable in your header as:
extern
const std::vector<std::function<void(const std::string&, const std::string&)>> m_myVector;