小编Kar*_*ary的帖子

C++模板和指针

我有模板和指针的问题(我认为).以下是我的代码的一部分:

/* ItemCollection.h */

#ifndef ITEMCOLLECTION_H
#define ITEMCOLLECTION_H

#include <cstddef>

   using namespace std;

   template <class T> class ItemCollection
   {
   public:
    // constructor
        //destructor 

     void insertItem( const T );

   private:
         struct Item
         {
          T price;
          Item* left;               
          Item* right;          
         };
         Item* root;     
         Item* insert( T, Item* );

   };
 #endif
Run Code Online (Sandbox Code Playgroud)

和具有功能定义的文件:

/* ItemCollectionTemp.h-member functions defintion */

#include <iostream>
#include <cstddef>

#include "ItemCollection.h"

template <class T>
   Item* ItemCollection <T>::insert( T p, Item* ptr)
   {
      // function body
   }
Run Code Online (Sandbox Code Playgroud)

以下是此行代码生成的错误:

Item* ItemCollection <T>::insert( T …
Run Code Online (Sandbox Code Playgroud)

c++ templates pointers

4
推荐指数
2
解决办法
3124
查看次数

标签 统计

c++ ×1

pointers ×1

templates ×1