×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / What's the actual type passed as T to instanciate X? This puzzled me!
    template<typename T>
    class X
    {
    };

    template<template<typename U> class T1, typename T2>
    class Y
    {
    };

    Y<X, int> aY;

    int main()
    {
    }
    • up一下
    • what C++ are you using? VC++?
    • I think it should be -- Y<X<aT>, int> aY;
      • that's what I was thinking about,but doesn't work.
    • look at this you'll understand what X takes. it actually can take anything.
      template<class T>
      class X
      {
      public:
      T a;
      };

      template<template<typename U> class T1, class T2>
      class Y
      {
      public:
      T1<float> b;

      };
      X<int> x;
      Y<X, int> aY;

      int main()
      {

      return 0;
      }
      • may i specify the float (... T1<float> ...) until I want to create aY?
        otherwise, if i fixed written T1<float>b, I can't have a T1<int> b, this lose the meaning for T1 to have a template parameter of U.
        Did I express myself clearly?
        • you should do this.
          ....

          template<template<typename U> class T1 , class T2>
          class Y
          {
          public:
          T1<T2> b;

          };

          Y<X, int> aY;

          .....
          • COOL!
            • another way, actually same thing, but it's clearer
              template<class T1, typename T2=X<T1> >
              class Y
              {
              public:
              T2 a;
              };