1

I have a template class as given below in a.hpp file.

template < typename GraphR,
       typename AbsV,
       typename GraphT = GraphTs< GraphR > >
class ForwardF {

   public:
  class AbsVC{
          Some definitions};

};

I have another class where I want to use the AbsVC type as given below.

#include <a.hpp>

template < typename GraphR,
       typename AbsV,
       typename GraphT = GraphTs< GraphR > >
class Interleave
: public ForwardF< GraphR, AbsV, GraphT > {


private:
  using InTable = std::unordered_map< GraphT, std::vector<AbsVC>>;

 };

I am getting error that AbsVC is not defined in this scope. Notice that the ForwardF is the base class and Interleave is derived class. So AbsVC which is defined in the base class should be visible in the derived class. Please tell me how to solve this problem.

  • 1
    There are a *whole* lot of types here that are unnecessary to the problem. Please try to make it easy for us to test and experiment with your code by creating an [MCVE](https://stackoverflow.com/help/mcve). Right now, we have to go to a lot of effort to remove all of the irrelevant `GraphTs`, `interleave_fwd_impl` nonsense to be able to compile. – Silvio Mayolo May 08 '19 at 04:01

1 Answers1

3

So AbsVC which is defined in the base class should be visible in the derived class.

This is true for normal classes but not for template classes.

You need to specifically mention that AbsVC is a typename that is dependent on the the class template ForwardF with certain template parameters.

So you can do this within the class template Interleave.

using AVC = typename ForwardF<GraphR, AbsV, GraphT>::AbsVC;

and then define InTable as:

using InTable = std::unordered_map< GraphT, std::vector<AVC>>;

This should work. Since I do not have a MCVE, I could not verify it.

P.W
  • 26,289
  • 6
  • 39
  • 76
  • Is the `typename` required in the line `using AVC = typename ForwardF::AbsVC;`? Please explain why it is required. – world_of_science May 08 '19 at 04:58
  • The keyword `typename` is used to specify that the identifier that follows is a type. For more info, see this [post](https://stackoverflow.com/questions/7923369/when-is-the-typename-keyword-necessary) and related duplicates. – P.W May 08 '19 at 05:01
  • The second `using` is not using any `typename` though `InTable` is also a type. – world_of_science May 08 '19 at 05:11
  • The `typename` is used to indicate what **follows** it is a type. In the first statement it is used to specify that `ForwardF::AbsVC;` is a type. – P.W May 08 '19 at 05:13