编译器抛出警告implicit typename is deprecated,百思不得其解,请大虾指教
小弟初学C++,在实现一个二叉搜索树一部分时遇到警告
from main.cpp:1:
source.template:30: warning: `mytree::bag<Item>::size_type' is implicitly a
typename
source.template:30: warning: implicit typename is deprecated, please see the
documentation for details
source.template:37: warning: `mytree::bag<Item>::size_type' is implicitly a
typename
source.template:37: warning: implicit typename is deprecated, please see the
main.o - 0 error(s), 8 warning(s)
请列位大虾不吝赐教,小弟不胜感激
源文件如下
bag.h
#ifndef _MAIN_BAG
#define _MAIN_BAG
#include <cstdlib>
#include "tree.h"
namespace mytree
{
template <typename Item>
class bag
{
public:
typedef std::size_t size_type;
typedef Item value_type;
//CONSTRUCTORS AND DESTRUCTOR
bag();
bag(const bag& source);
~bag();
//MODIFICATION functions
size_type erase(const Item& target);
bool erase_one (const Item& target);
void insert(const Item& entry);
void operator +=(const bag& addend);
void operator =(const bag& source);
//CONSTANT functions
size_type size() const;
size_type count(const Item& target) const;
private:
tree<Item> *root_ptr;
size_t many_nodes;
};
template <typename Item>
bag<Item> operator +(const bag<Item>& b1,const bag<Item>& b2);
}
#include "source.template"
#endif
source.template
#include <cassert>
#include <cstdlib>
#include <iomanip>
#include <iostream>
namespace mytree
{
template <typename Item>
bag<Item>::bag()
{
root_ptr=NULL;
many_nodes=0;
}
template <typename Item>
bag<Item>::bag(const bag& source)
{
tree_copy(source.root_ptr);
root_ptr=source.root_ptr;
}
template <typename Item>
bag<Item>::~bag()
{
tree_clear(root_ptr);
}
template <typename Item>
bag<Item>::size_type bag<Item>:: size()const
{
return tree_size (root_ptr);
}
template <typename Item>
bag<Item>::size_type bag<Item>:: count(const Item& target) const {
size_type answer;
const tree<Item>* cursor;
answer=0;
cursor=root_ptr;
while (cursor!=NULL)
{
if (target<cursor->data())
cursor=cursor->left();
if(target>cursor->data())
cursor=cursor->right();
while(target==cursor->data())
{
++many_nodes;
cursor=cursor->left();
}
}
if (cursor==NULL)
return many_nodes;
}
template <typename Item>
void bag<Item>::operator =(const bag& source)
{
if (this==&source)
return;
tree_clear(root_ptr);
many_nodes=0;
tree_copy(source.root_ptr);
many_nodes=source.many_nodes;
}
}