Is there equivalent of <? extends T>, <? super T> in C++?

后端 未结 5 1652
忘了有多久
忘了有多久 2021-02-05 10:33
  1. Is there equivalent of , in C++?

  2. Also, does ,

5条回答
  •  情歌与酒
    2021-02-05 11:23

    This worked for me:

    #include 
    
    class MyBase {}; 
    class A : public MyBase {};    
    class B {};
    
    template 
    typename std::enable_if::value>::type
    Foo(T &v) {
        std::cout << "Foo 1" << std::endl;
    }
    
    template 
    typename std::enable_if::value>::type
    Foo(T &v) {
        std::cout << "Foo 2" << std::endl;
    }
    
    int main() {
      A a;
      B b;
      Foo(a);
      Foo(b);
      return 0;
    }
    

提交回复
热议问题