1

for non-template class, I can use forward declaration in the header file. But it gave me error when I use it in the template class.

I have to include the header file, I would like to know the reason.

class Pu;

template <typename T>
class Pt()
{
     void test(Pu<T> u);
}
Adam Lee
  • 23,314
  • 47
  • 144
  • 221

1 Answers1

6

It works just fine, if you do it properly!

Remember, Pu is a class template, not a class, so it must be declared as such:

template <typename T>      // N.B. this line
class Pu;

template <typename T>
class Pt                   // N.B. no "()"
{
     void test(Pu<T> u);
};                         // N.B. ";"

(live demo)

Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021