#include <iostream>

template <int dim, template <int> class BImp>
struct B 
{
  enum { dimension = dim };
  template <int cd> 
  struct Traits 
  {
    typedef BImp<dim> BType;
  };

};

template <int dim> 
struct A : public B <dim,A> 
{
  template <int codim>
  A<codim> getA_T () 
  {
    // just fake 
    A<codim> tmp;
    return tmp; 
  }

  A<0> getA () 
  {
    // just fake 
    
    A<0> tmp;
    return tmp; 
  }
 
};

template <> template <>
inline A<0> A<0>::getA_T<0>()
{
  // just fake 
  enum {dim = 0};
  typedef Traits<dim>::BType BType;

  A<dim> tmp;
  return tmp;
}

template <class T> 
void foo ( T & t)
{
  typedef typename T::Traits<0>::BType BType;
  BType b1 = t.getA ();

  BType b2 = t.template getA_T<0> ();

  std::cout << "called A::foo () !\n";
}

int main ()
{
  A<0> a;
  foo(a); 
}

