C ++ Forward declare using directive

I have a header that provides a template class and typedef with for example:

namespace fancy {

  struct Bar {
     ...
  }

  template<typename T>
  class Foo {
     ...
  }

  using FooBar = Foo<Bar>;
}

I would like to pass declare FooBarto use it in shared_ptra different header. I tried

namespace fancy {
  using FooBar;
}

both for class or structure, but no luck. Is this possible, and if so, how?

+4
source share
1 answer

You cannot declare an alias usingwithout defining it. However, you can declare your template template without defining it and use a duplicate using:

namespace fancy {
    template <typename> class Foo;
    class Bar;
    using FooBar = Foo<Bar>;
}
+8
source

All Articles