Using a templated parameter's value_type

后端 未结 3 1592
-上瘾入骨i
-上瘾入骨i 2021-02-13 01:54

How is one supposed to use a std container\'s value_type?
I tried to use it like so:

#include 

using namespace std;

template 

        
3条回答
  •  星月不相逢
    2021-02-13 01:54

    Here is a full implementation of the accepted answers above, in case it helps anyone.

    #include 
    #include 
    
    template 
    class C1 {
      private:
        T container;
        typedef typename T::value_type CT;
      public:
        void push(CT& item) {
            container.push_back(item);
        }
    
        CT pop (void) {
            CT item = container.front();
            container.pop_front();
            return item;
        }
    };
    
    int main() {
        int i = 1;
        C1 > c;
        c.push(i);
        std::cout << c.pop() << std::endl;
    }
    

提交回复
热议问题