A
A
Avery0072015-08-01 15:43:55
C++ / C#
Avery007, 2015-08-01 15:43:55

Is it possible to export templates from dll?

I need to implement the Vector2 class for different types, but I'm too lazy to write the implementation of methods for each manually. It would be reasonable to use templates, but I need to export this class.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ruchkin, 2015-08-02
@VoidEx

You can, if you instantiate templates explicitly for predefined types, for example:

template <typename T> struct Vector { ... };
template <typename T> void foo(Vector<T> &); // definition in cpp

template struct Vector<Point2d>;
template struct Vector<Point3d>;

template void foo<Point2d>(Vector<Point2d> &);
template void foo<Point3d>(Vector<Point3d> &);

Structures Vector<Point2d>and Vector<Point3d>will be exported.

S
Stanislav, 2015-08-01
@crackedmind

You can't do that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question