编译器抛出警告implicit typename is deprecated,百思不得其解,请大虾指教

foreverlovezyn 2008-03-28 09:38:40
小弟初学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;
}

}
...全文
150 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
foreverlovezyn 2008-03-29
  • 打赏
  • 举报
回复
哦,是这样。谢谢
hityct1 2008-03-29
  • 打赏
  • 举报
回复
typedef std::size_t size_type;

因为编译器无法知道size_t是个变量还是型别,所以加上 typename指明是size_t
是型别
foreverlovezyn 2008-03-28
  • 打赏
  • 举报
回复
嗯,原理我还不太明白,加上之后就不是隐式的了吗?
foreverlovezyn 2008-03-28
  • 打赏
  • 举报
回复
好厉害,这么快! 解决了,多谢大虾!
我啃 2008-03-28
  • 打赏
  • 举报
回复
加typename 关键字
相关推荐
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-03-28 09:38
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下