c++ - How can I define the function body in a .h file? -


sometimes define bodies of small global functions in .h files (static inline). works.

now have larger global function. need to define in .h file. not want static inline. tried following trick "dummy template":

template <typename tunused> int myfunction(...) {     ... } 

to achieve -- define global function in .h file.

compiler complains "cannot deduce template argument 'unused'".

do guys understand trying ? how can trick compiler ? think need unsert dummy usage of template arg function compiler can deduce it.

can ?

honestly, don't recommend putting large non-template function's definition in .h file unless there definite reason can't put definition in .cpp file. if have put definition in .h, following code might help:

// .h template< int unused > int myfunction_() {   // definition }  namespace { int (&myfunction)() = myfunction_<0>; }  // .cpp int main() { myfunction(); } 

if show reason have put definition in .h, better suggestions may posted.

edit: rewrote code in light of bo persson's pointing out.


Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

jQuery clickable div with working mailto link inside -