Explicit function template creation fails (g ++)

I am having some problems (i.e. communication errors) with the explicit specification of the function template. In Visual Studio, the project connects normally, only under g ++ / Unix, using Eclipse-CDT, communication creates errors.

A function call is part of a static library that is linked to a dynamic library in a large project. The architecture of the function is as follows:

  • the function template is declared (but not implemented) inside the namespace in my file MathUtils.h. One of the function arguments is the structure template itself, declared and implemented in this hfile (in the same namespace).
  • implementation of a function and its creation c MathUtils.cpp.
  • the function call is in someFile.cpp(which, of course #include "MathUtils.h"), which is compiled and linked as part of the static library.

The thing that drives me crazy (almost) insane is that the assembly errors are not completely reproducible, and I suspect that Eclipse should be blamed (maybe skip some steps, although I use them clean projectbefore every assembly).

After about an hour, the Debug configuration was built without errors, but Release failed undefined reference to.... Then, over the next hour, both configurations failed. Then I made a small project with the three files mentioned above, and compiled it both from the command line and from Eclipse - no errors at all. Now both configurations seem to be connected approx.

- Eclipse-CDT? ?

EDIT: ( ) , , . , .

+3
2

. , .cpp .

myclass.hpp:

template <class T>
class MyClass
{
public:
    MyClass();
    // other declarations
};

myclass.cpp:

#include "myclass.hpp"

template <class T>
MyClass<T>::MyClass()
{
}

template class MyClass<int>;
template class MyClass<bool>;
+3

www.cplusplus.com

, , : () . , , , , .

-2

Source: https://habr.com/ru/post/1778791/


All Articles