簡體   English   中英

具有函數的c ++中的類模板

[英]class template in c++ with functions

#AL.hpp
template <typename A>
class AL
{
    public:
        void print(A *source, A *dest, unsigned int size);
    private:
        A *data;
        unsigned int size;
        unsigned int capacity;
 }

namespace {
    template <typename A>
    unsigned int size s_size = 20;
    void print(A *source, A *dest, unsigned int size)
    {
      ....
    }
 }

template <typename A>
AL<X>& AL<X>::push(A input)
{
    capacity *= 2;
    A *new_data = new A[capacity];
    print(data, new_data, size);
 }

我只是想知道如何格式化它(請不要介意代碼)。 當我運行完整的代碼時,它表示未在名稱空間中定義A。 我不確定如何將類模板傳遞給我的命名空間。

#AL.hpp
template <typename A>
class AL
{
    public:
        AL(A array_list);
        AL(const AL& other);
        AL& operator=(const AL& other);
        ~AL;
        void print(A *source, A *dest, unsigned int size);
}

namespace {
    unsigned int size s_size = 20;
    template <typename A>
    void print(A *source, A *dest, unsigned int size)
    {
       ....
    }
 }

如果問題或錯誤是您的``打印''功能似乎未命名,那么這就是解決方案。我希望這會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM