Inconsistent template context

template<typename T>
struct Wrap {
  Wrap(T *p) {}
};

#ifdef TEMPLATE
template<typename T>
void foo (Wrap<T> t) {}  // version-1

#else
void foo (Wrap<int> p) {} // version-2
#endif

int main () {
  foo(new int);
}

When the part is #elsecompiled, the compilation is fine and version-2 is selected. If I try to compile the part #ifdef, I expect version-1 to be selected. However, the compiler gives an error like,

error: there is no corresponding function to call `foo (int *) '

Am I touching the non deduction part template foo? If so, can anyone clarify what is the exact rule of the area not deduced ?

+5
source share
1 answer

, . , , , Wrap .

#else Wrap<int>, Wrap<int>(int*).


, : , , .

+3

All Articles