0
#include <vector>

template < class a > class innervec {
    inner();
    ~inner();

    std::vector<a> innerdata;
};

template < class a, template <class a> class inner > class outer {
    outer();
    ~outer();

    a *myPtr;
    inner<a> myInner;
};

//Edit to provide examples

template < class a > class innerlist {
     otherinner();
     ~otherinner();
    
    std::list<a> innerdata
}

//call sites

//Use outer with vector inner with int type
outer<int, innervec> OuterWithVec()

//Use outer with list inner with double type
outer<double, innerlist> OuterWithList()

https://godbolt.org/z/j3ofqE4fj

Similar question Can a parameter of a template template parameter cause shadowing?

I'm attempting to refactor some code, and with a newer compiler I get this error. I understand that is not valid C++, but The original question doesn't seem to directly answer "What is the correct solution?"

In this case I simply want to pass the same template parameter to the inner template parameter, right now my outer template class only has a pointer of the template type, and a member of type "inner templated class" where the inner parameter is simply passed through. (I think this was the original purpose of this design).

Joshua
  • 374
  • 3
  • 17
  • 3
    The thing is that "pass the template parameter to the inner template parameter" is not a logical statement. The "inner template" is an independent template that takes one template parameter. There's nothing to "pass". The only time `a` might come into play would be when ***instantiating*** the inner template. That's something that ***doesn't*** happen in a template declaration. So, it's unclear what this is supposed to do. Simply remove the inner template parameter's name. The End. – Sam Varshavchik Jul 07 '21 at 00:03
  • 2
    I'm not sure what the issue is. Why are you naming the type of the template template parameter at all? What are you trying to do with that? – cigien Jul 07 '21 at 00:04
  • @SamVarshavchik That is quite likely the answer. – Captain Giraffe Jul 07 '21 at 00:05
  • 1
    Look at your error message. The compiler points to the two things named `a` that are problematic. To which of these two things do you want to refer in the two lines where you *use* `a`? (The two lines are the definitions of `myPtr` and `myInner`.) Once you know that, ask yourself why the other thing needs to have the same name, or even a name at all. – JaMiT Jul 07 '21 at 00:45
  • @SamVarshavchik So I guess I meant to say, the original intent looks like "I defined a class that has a templated type as a member, as well as containing a member of the templated parameter type directly." "I need to ensure that the type of the inner and the type of the member agree" – Joshua Jul 07 '21 at 12:54
  • @cigien so what name are you talking about, and why don't I need it? – Joshua Jul 07 '21 at 12:55
  • @JaMiT I think I see what you're saying – Joshua Jul 07 '21 at 12:56
  • Your class currently takes 2 template parameters, and there's no relationship between them (until you use the first as a parameter for the second inside the class). Can you please add an example of how you want to use this class? What does it look like at the call site? – cigien Jul 07 '21 at 12:59
  • @cigien updated with example usage – Joshua Jul 07 '21 at 14:17

0 Answers0