代码之家  ›  专栏  ›  技术社区  ›  nakiya

如何转发声明命名空间std中的模板类?

  •  127
  • nakiya  · 技术社区  · 14 年前
    #ifndef __TEST__
    #define __TEST__
    
    namespace std
    {
        template<typename T>
        class list;
    }
    
    template<typename T>
    void Pop(std::list<T> * l)
    {
        while(!l->empty())
            l->pop();
    }
    
    #endif
    

    在我的主系统中使用了这个功能。我有错误。当然,我知道有更多的模板参数用于 std::list (我想是分配器)。但是,这不是重点。我必须知道模板类的完整模板声明才能转发声明它吗?

    编辑:我以前没有用过指针-它是一个参考。我用指针试试看。

    4 回复  |  直到 7 年前
        1
  •  138
  •   Jon Purdy    11 年前

    namespace std {
      template<class T, class Allocator = std::allocator<T>>
      class list;
    }
    

    namespace std std std::less

    #include <list>

    TEST_H __TEST__

        2
  •  20
  •   Littm JessicaParker    12 年前

    <class T>

    *.cpp

    ifndef STATE_H_
    #define STATE_H_
    #include <stdlib.h>
    #include "Frame.h"
    
    template <class T>
    class LinkFrame;
    
    using namespace std;
    
    template <class T>
    class State {
    
      protected:
        LinkFrame<int> *myFrame;
    
    }
    

    #include "State.h"
    #include "Frame.h"
    #include  "LinkFrame.h"
    
    template <class T>
    bool State<T>::replace(Frame<T> *f){
    

        3
  •  10
  •   Grozz    14 年前

        4
  •  -5
  •   Arne    11 年前

    class std_int_vector;
    
    class A{
        std_int_vector* vector;
    public:
        A();
        virtual ~A();
    };
    

    #include "header.h"
    #include <vector>
    class std_int_vector: public std::vectror<int> {}
    
    A::A() : vector(new std_int_vector()) {}
    [...]