隐式类型模板警告 [英] implicit type template warning

查看:64
本文介绍了隐式类型模板警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人可以向我解释为什么我收到此警告信息以及我如何解决此警告信息。


非常感谢


Johan


成员函数`void

Callback1< Par> ; :: search()'':

b.cpp:44:警告:`typename std :: vector< Callback< Par>,

std :: allocator<回调<帕> > > :: iterator''含义为

typename

b.cpp:44:警告:不推荐使用隐式typename,请参阅

详细信息文档

模板< class Par>

类回拨

{

public:

回调(const Par& par):par(par)

{

}

~回调()

{

}


void show()

{

cout< ;< par<< endl;

}


私人:

par par;

};

模板< class Par>

class Callback1:public Callback< Par>

{

public:

typedef回调< Par> CallbackPar;


Callback1(const Par& par):回调< Par>(par)

{

v.push_back( par);

}

~Callback1()

{

}


无效搜索()

{

vector<回调< Par> > :: iterator i;

}


私人:

vector<回调< Par> > v;

};


b.cpp:在成员函数中`void Callback1< Par> :: search()'':

b.cpp:44:警告:`typename std :: vector< Callback< Par>,

std :: allocator< Callback< Par> > > :: iterator''含义为

typename

b.cpp:44:警告:不推荐使用隐式typename,请参阅

详细文档

解决方案



Johan写道:


<有人可以向我解释为什么我收到此警告信息以及我如何解决此警告信息。
在成员函数中`void
Callback1< Par> :: search()'':
b.cpp:44:警告:`typename std :: vector< Callback< Par>,
std :: allocator< Callback< Par> > > :: iterator''是隐含的
typename
b.cpp:44:警告:不推荐使用隐式typename,详情请参阅
文档
....模板< class Par>
类Callback1:public Callback< Par> {
void search(){
vector<回调< Par> > :: iterator i;




当然。迭代器,模板,变量或类型是什么类型的名称

(枚举/ typedef /嵌套类)?只有当它知道Par是什么时,编译器才会知道这个,但是当编译模板时,这还不知道是否已知。 Par将在稍后的实例化期间提供。


警告告诉你编译器猜到了,它正确地猜到了

。 iterator是一个typename。为了防止警告,请明确显示并输入自己的类型名称。

BTW,警告说RTFM,它不是包括这个吗? />
问候,

Michiel Salters




" msalters" <弥************* @ logicacmg.com>在留言新闻中写道:11 ********************* @ c13g2000cwb.googlegro ups.com ...


Johan写道:



有人可以向我解释为什么我收到此警告信息以及我如何解决此警告信息。

在成员函数中`void
Callback1< Par> :: search()'':
b.cpp:44:警告:`typename std :: vector< Callback< ; Par>,
std :: allocator< Callback< Par> > > :: iterator''是隐含的
typename
b.cpp:44:警告:不推荐使用隐式typename,详情请参阅
文档


...

template< class Par>
class Callback1:public Callback< Par> {
void search(){
vector<回调< Par> > :: iterator i;



当然。迭代器,模板,变量或类型是什么类型的名称
(enum / typedef / nested类)?编译器只有在知道Par是什么时才知道这一点,但是当编译模板时,这还不知道。 Par将在实例化期间稍后提供。

警告告诉您编译器猜到了,并且它正确地猜到了
。 iterator是一个typename。为了防止警告,请明确并将类型名称放在自己。




所以,

typename vector<回调< Par> > :: iterator i;


可以用别的东西代替''typename''吗?


[snip]

-

Alex Vinokur

电子邮件:alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn



Alex Vinokur写道:

所以,
typename vector<回调< Par> > :: iterator i;

可以用其他东西代替''typename''吗?




如果你不包括''typename''编译器必须假设它

是一个值。对于标准类,这似乎是不可行的

,因为你很难在不违反其他规则的情况下获得除了类型

之外的其他内容,但同样的规则适用于此

用户定义的类型。对于这些,在上下文中具有

值或类型非常容易,并且编译器可以在没有

类型名称的情况下仅检测实例化类型的正确含义。

-

< mailto:di *********** @ yahoo.com> < http://www.dietmar-kuehl.de/>

< http://www.contendix.com> - 软件开发&咨询


Hi

Can somebody explain to me why I get this warning message and how I
can solve this warning message.

Thanks a lot

Johan

In member function `void
Callback1<Par>::search()'':
b.cpp:44: warning: `typename std::vector<Callback<Par>,
std::allocator<Callback<Par> > >::iterator'' is implicitly a
typename
b.cpp:44: warning: implicit typename is deprecated, please see the
documentation for details
template <class Par>
class Callback
{
public :
Callback(const Par& par) : par(par)
{
}
~Callback()
{
}

void show()
{
cout << par << endl;
}

private :
Par par;
};
template <class Par>
class Callback1 : public Callback<Par>
{
public :
typedef Callback< Par > CallbackPar;

Callback1(const Par& par) : Callback<Par>(par)
{
v.push_back(par);
}
~Callback1()
{
}

void search()
{
vector< Callback< Par > >::iterator i;
}

private :
vector< Callback< Par > > v;
};

b.cpp: In member function `void Callback1<Par>::search()'':
b.cpp:44: warning: `typename std::vector<Callback<Par>,
std::allocator<Callback<Par> > >::iterator'' is implicitly a
typename
b.cpp:44: warning: implicit typename is deprecated, please see the
documentation for details

解决方案


Johan wrote:

Hi

Can somebody explain to me why I get this warning message and how I
can solve this warning message. In member function `void
Callback1<Par>::search()'':
b.cpp:44: warning: `typename std::vector<Callback<Par>,
std::allocator<Callback<Par> > >::iterator'' is implicitly a
typename
b.cpp:44: warning: implicit typename is deprecated, please see the
documentation for details .... template <class Par>
class Callback1 : public Callback<Par> {
void search() {
vector< Callback< Par > >::iterator i;



Sure. What kind of name is iterator, a template, a variable, or a type
(enum/typedef/nested class)? The compiler will know this only when it
knows what Par is, but when the template is compiled this isn''t yet
known. Par will be provided later during instantiation.

The warning tells you that the compiler guessed, and it guessed
correctly. iterator is a typename. To prevent the warning, be
explicit and put the typename in yourself.
BTW, the warning said "RTFM", didn''t it include this?
Regards,
Michiel Salters



"msalters" <Mi*************@logicacmg.com> wrote in message news:11*********************@c13g2000cwb.googlegro ups.com...


Johan wrote:

Hi

Can somebody explain to me why I get this warning message and how I
can solve this warning message.


In member function `void
Callback1<Par>::search()'':
b.cpp:44: warning: `typename std::vector<Callback<Par>,
std::allocator<Callback<Par> > >::iterator'' is implicitly a
typename
b.cpp:44: warning: implicit typename is deprecated, please see the
documentation for details


...

template <class Par>
class Callback1 : public Callback<Par> {
void search() {
vector< Callback< Par > >::iterator i;



Sure. What kind of name is iterator, a template, a variable, or a type
(enum/typedef/nested class)? The compiler will know this only when it
knows what Par is, but when the template is compiled this isn''t yet
known. Par will be provided later during instantiation.

The warning tells you that the compiler guessed, and it guessed
correctly. iterator is a typename. To prevent the warning, be
explicit and put the typename in yourself.



So,
typename vector< Callback< Par > >::iterator i;

Can something else be instead of ''typename''?

[snip]
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn



Alex Vinokur wrote:

So,
typename vector< Callback< Par > >::iterator i;

Can something else be instead of ''typename''?



If you don''t include ''typename'' the compiler has to assume that it
is a value. For standard classes this may seem to be unreasable
because you have a hard time to get something else than a type
without violating some other rule but the same rule applies here
as to user defined types. For these it is pretty easy to have a
value or a type in a context and the compiler could, without the
typename, only detect the correct meaning at instantiation type.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting


这篇关于隐式类型模板警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆