views:

44

answers:

1

This compiled on VS 2008, but it seems like non-standard usage of templates.

template <class T>
class Foo
{
public:
  void bar(Foo<int> arg)
  {
    // do some stuff here
  }

  // more code ...
};

Is there an issue since the template specialization Foo<int> is contained within the definition of its own template class?

+4  A: 

It's not really specialisation - you are just saying that function takes a parameter of type Foo <int> - the fact that the function is itself a member of the Foo class isn't really important. And yes, it's legal.

anon
He was using the correct term, though. `Foo<int>` is a class template specialization reference (generated specialization when instantiated, but can be a reference to an explicit specialization). But i suspect, like you, that he was meaning explicit specializations, but accidentally confused it with the general template specialization term. That's what we get from C++'s complex definitions :)
Johannes Schaub - litb
@Johannes You are right of course, but I think most people would refer to it (possibly wrongly) as an instantiation. Anyway, my use of the word "really" as intended to cover all bases :-)
anon