Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

template specialized on a namespace

Given:

namespace A {
  class Foo;
  class Bar;
}

namespace B {
  class Foo;
  class Bar;
}

I want to template a class on the namespace A or B such that the following works:

template<name> class C {
  name::Foo* foo;
  name::Bar* bar;
}

Can this be done directly or do I need to create a pair of struct types with typedefs in them?

like image 383
BCS Avatar asked Aug 24 '10 16:08

BCS


2 Answers

You can't template on a namespace. If you're able to use a class (with most likely public attributes/static methods) then you can template on the class as a semi-workaround.

like image 112
Mark B Avatar answered Sep 22 '22 13:09

Mark B


No, templates can't be parametrized on a namespace.

like image 26
Dr. Snoopy Avatar answered Sep 25 '22 13:09

Dr. Snoopy