... 当然。迭代器,模板,变量或类型是什么类型的名称(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 如果你不包括''typename''编译器必须假设它 是一个值。对于标准类,这似乎是不可行的 ,因为你很难在不违反其他规则的情况下获得除了类型 之外的其他内容,但同样的规则适用于此 用户定义的类型。对于这些,在上下文中具有 值或类型非常容易,并且编译器可以在没有 类型名称的情况下仅检测实例化类型的正确含义。 - < mailto:di *********** @ yahoo.com> < http://www.dietmar-kuehl.de/> < http://www.contendix.com> - 软件开发&咨询 HiCan somebody explain to me why I get this warning message and how Ican solve this warning message.Thanks a lotJohanIn member function `voidCallback1<Par>::search()'':b.cpp:44: warning: `typename std::vector<Callback<Par>,std::allocator<Callback<Par> > >::iterator'' is implicitly atypenameb.cpp:44: warning: implicit typename is deprecated, please see thedocumentation for detailstemplate <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 atypenameb.cpp:44: warning: implicit typename is deprecated, please see thedocumentation for details 解决方案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 itknows what Par is, but when the template is compiled this isn''t yetknown. Par will be provided later during instantiation.The warning tells you that the compiler guessed, and it guessedcorrectly. iterator is a typename. To prevent the warning, beexplicit and put the typename in yourself.BTW, the warning said "RTFM", didn''t it include this?Regards,Michiel Salters ... 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 Vinokuremail: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvnIf you don''t include ''typename'' the compiler has to assume that itis a value. For standard classes this may seem to be unreasablebecause you have a hard time to get something else than a typewithout violating some other rule but the same rule applies hereas to user defined types. For these it is pretty easy to have avalue or a type in a context and the compiler could, without thetypename, only detect the correct meaning at instantiation type.--<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/><http://www.contendix.com> - Software Development & Consulting 这篇关于隐式类型模板警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS! 05-22 08:19