Undefined static template method definitions in C ++?

Is it possible to call a static template function that is not a member from a static member function, where the definition is split into a header and cpp:

// zero.cpp

class Zero
{
    static void zero() { one(5); }
};

// one.h

template <typename T>
static void one(T& var);

// one.cpp

template <typename T>
void one(T& var) { }

// main.cpp

...

Zero::zero()

...

I am having problems with this to bind, I keep getting an undefined reference to the function that I am trying to define in one.cpp.

Initially, I thought this was due to a problem with the namespace, but all the files are now in the same namespace. Am I doing something fundamentally wrong here?

+3
source share
2 answers

. , - :

// one.hpp

template <typename T>
static void one(T& var)
{
    // definition visible in header
}

, , .

+4

GMan- , T& rvalue, , 5, int. 5 int&, const int&.

+2

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


All Articles