Questions about templates and headers

The compiler says that it cannot find the link for the function when I do this:

// link.h
template <class T>
    T *Link(T *&, T *(*)())

// link.cpp
template <class T>
T c:Link(T *&ChildNodeReference, T *(*ObjectCreator)()){

}

If I implement inside the class in the title, it goes smoothly.

Please, I will work on the headline until someone enlightens me about this.

There is something in C ++ that is strangely annoying. I know there is a reason for this, etc. Even so, can compilers help you about this? _ "

+2
source share
5 answers

- Bad Thing ™. , cpp, , , .

, , , .

( List<int>), , .

, , , , , . , , , CPP , .

, , .

+5

- , , , -, .

( ) , /, , , , .

++ . , "", , , ( ). , . :

struct t1 {
  template <int>
  struct a {};
};

struct t2 {
  enum { a = 123 }; 
};

enum { b = 456, c = 789 };

template <class T>
void foo() {
   T::a<b>c;
}

, foo<t1>(), , t1::a :

T::a<b> c;

foo<t2>(), , t2::a :

(T::a < b) > c;

, , "" ; .

, , , ISO ++ , , .h .cpp . " ", export:

// link.h
export template <class T>
T *Link(T *&, T *(*)());

// link.cpp
export template <class T>
T *Link(T *&ChildNodeReference, T *(*ObjectCreator)()) {
}

, , - , ; , g++, MSVC ++ Builder . , , Comeau ++.

+6

( ) .

, .

+4

. , ! ( , ++ : P)

0

* . , . , :

T *c:Link(T *&ChildNodeReference, T *(*ObjectCreator)())
{
}

, .

0

All Articles