I am using C++ for some sequence data analysis, and have found it hard to call functions across files. Say I have a file A.cpp with an associated header A.hpp. A.cpp has a Main() function and a function My_Func() that I hope to reuse in B.cpp, which also has a Main() function. My question is, how do I call My_Func() from B.cpp? I am not allowed to compile A.cpp and link it with B.cpp since it will create two entry points (two mains) for the program.
The solution I can think of is to implement My_Func() in A.hpp instead of A.cpp and include A.hpp in B.cpp, i.e. to go header only. But that seems to be very inefficient (though acceptable). I think there should be better solutions, i.e. in python I can just do from A import My_Func. I am wondering what would be a canonical way to deal with this issue cleanly? Thanks in advance!