0

Let's suppose i have a template class like this:

template <class T>
class Foo{
void print(){
  ::print(T);
}
private:
T data;
}

And this class situated in h file and compiled to static library.

Then i have few more modules, that have linked with this static library and i'm using this Foo class in them.

Is there any way to define specific print function in that modules ? Or I should define global print with specific instantiation only beside Foo class?

tty6
  • 1,203
  • 11
  • 30
  • BTW, `templates` don't get compiled to machine instructions on their own. So the "static library" thing is not something to worry about. Your class is as good as ``. They have to be instantiated using some types. Hence even if this `class` is situated in a .h file, it's just a text. Only when you do something like `Foo`, the "real" code generation happens. – iammilind Aug 24 '16 at 09:42
  • 1
    *"Is there any way to define specific print function in that modules?"*. Ofcourse there are ways. You can overload those `::print()`s for the desired type in any of the modules. Depending on whichever places, these global function of printing is visible, it will be instantiated. @πάνταῥεῖ, it will be good for the future visitors, if you can brief about the duplicacy of this Q with the linked one. I am little doubtful about it. Probably the OP is asking something specific. Hence, your comment on it will be valuable. – iammilind Aug 24 '16 at 10:26

0 Answers0