Tuesday, March 15, 2011

Simple c++ question. Is "T" class or template?




#include <iostream>

template <class T> // (1)
class B
{
public:
  void foo(T* t); // (2)
};
 
class T // (3)
{
public:
  int i;
};
 
void B<T>::foo(T* t) // (4)
{
  std::cout << t->i << std::endl;
}
 
int main()
{
  B<T> b; // (5)
  T t;
  t.i = 3;
  b.foo(&t);
}

1 comment:

gilgil said...

(1) : template
(2) : template
(3) : class
(4) : template
(5) : class

It is important to distingiush exactly template from class(including structure or basic ordinary type) in C++ code.