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
  • 24,710
  • 51
  • 156
  • 236

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
  • 378,754
  • 76
  • 643
  • 1,055