Re: Stuck trying to do first exercise in C++ Template Metaprogramming

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Patrick,

To simplify the problem, what you are basically trying to do is this:

------------------------------
struct Foo 
{
  template <bool x>
  struct MyTemplate
  {
    enum { test = false };
  };  

  template <>
  struct MyTemplate<true>
  {
    enum { test = true };
  };  
};
------------------------------

The MyTemplate<true> template specialization cannot be done inside the Foo
declaration.  It is not valid C++.

Instead, you should do the template specialization outside of the declaring
outer struct (or in your case, outside of the outer template class
declaration) like this:

------------------------------
struct Foo
{
  template <bool x>
  struct MyTemplate
  {
    enum { test = false };
  };
};

template <>
struct Foo::MyTemplate<true>
{
  enum { test = true };
};
------------------------------

Hope that helps,
--Eljay




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux