#include <string>
#include <functional>
#include <iostream>
constextern std::function<std::string(constchar*)> use_std_function;
constextern std::string use_function(constchar*);
int main(int argc, char** argv)
{
constchar* input = "Hello, world!";
{
std::string output = (use_function)(input);
if (output != input)
std::cerr << "Output does not equal input after use_function";
}
{
std::string output = (use_std_function)(input);
if (output != input)
std::cerr << "Output does not equal input after use_std_function";
}
return 0;
}
Command line:
g++ test.cpp my_func.cpp
Results:
1 2 3
/usr/bin/ld: /tmp/ccc0sxWt.o: in function `main':
test.cpp:(.text+0x7e): undefined reference to `use_std_function[abi:cxx11]'
collect2: error: ld returned 1 exit status
It seems use_function is working, as if I comment out use_std_function it compiles and runs. But I am not sure what I am doing wrong with the std::function. Any help is appreciated.
Additional note: #including my_func.cpp as if it were a header works, but is not what I am after.