Abruzzo Forte e Gentile
Abruzzo Forte e Gentile

Reputation: 14879

An issue with nesting template classes

I was trying to test the templated code below but I am getting the following error:

  error: ‘Foo’ is not a template

Is my code below correct? It looks the simplest template code I can possibly do!

  template<typename D>
  struct Ciccio{
  };

  template<typename S>
  struct Foo< Ciccio<S> >{
  };


int main(){
    typedef Ciccio<int> test_type;
    Foo<test_type> f;
    return 1;    
}

Upvotes: 1

Views: 51

Answers (1)

juanchopanza
juanchopanza

Reputation: 227608

As it stands, Foo looks like a partial template specialization. You need to provide a primary Foo class template:

template<typename D>
struct Ciccio {};

// primary template
template<typename S>
struct Foo;

// partial specialization
template<typename S>
struct Foo< Ciccio<S> > {};

int main(){
  typedef Ciccio<int> test_type;
  Foo<test_type> f;
}

Upvotes: 3

Related Questions