怀疑模板! [英] Doubt on template !

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

问题描述


我在模板方面遇到了一些问题.下面是一个示例.
MaxHeap< HeapNode< Typew,Typep>> * H;(1)
并且HeapNode的定义是:
template< class Typew,class Typep>(2)
类HeadNode
{
};
然后,我将其编译为(1)的4​​个错误.那么,您能告诉我(1)到底是什么意思吗?以及如何纠正这些错误.
非常感谢!


编辑(Nelek):答案4"中OP的附加信息

是的,我同意,这取决于视觉标准的版本.
现在,我使用VC 6.0.
而现在,我认为我可以找到此问题的关键因素.
那也许我应该先定义一个MaxHeap类.
您怎么看?

Hi,
I have got some problems about template.There is an example as following.
MaxHeap<HeapNode<Typew,Typep>> * H;(1)
and the definition of the HeapNode is:
template<class Typew,class Typep>(2)
class HeadNode
{
};
then,I compile it, 4 errors on(1).So,could you tell me what does (1)exactly mean? And How can I correct these errors.
Thank you very much !


EDIT (Nelek): Additional information of the OP in "Answer 4"

Yes, I agree,it depends on the version of visual stdio.
Now,I use the VC 6.0.
And right now, I think I can get the key factor of this problem.
That is maybe I should define a class of MaxHeap first.
What do you think?

推荐答案

第一个创建了Typew和Typep类型的堆节点堆.不确定为什么需要两种类型,而Typew和Typep应该是您定义的类型(看起来就像您在使用由HeapNode定义的类型一样).但是请记住,当您放置两个>时,C ++不喜欢.一两行<连续(将它们与流运算符混淆,因此您必须在它们之间放置一个空格),但是我想这可能取决于您使用的编译器.修改您的原始问题并发布您收到的错误消息.
Number one creates a heap of heap nodes of type Typew and Typep. Not sure why two types are needed, and Typew and Typep should be types you define (looks like you are just using the types as they are defined by HeapNode). But just keep in mind that C++ does not like when you put two > in a row or two < in a row (confuses them with stream operators, so you''ll have to put a space in between them), but I suppose that might depend on the compiler you use. Modify your original question and post the error messages you get.


您遇到的错误是什么?
您正在使用哪个版本的Visual Studio?
What are the errors that you get?
Which version of Visual Studio are you using?


如果使用的是较旧的编译器,请从替换开始:

If you are using an older compiler, start with replacing:

MaxHeap<HeapNode<Typew,Typep>>







with

MaxHeap<HeapNode<Typew,Typep> >



(请注意在右尖括号之间有一个多余的空间)



(note an extra space between the closing angle brackets)


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

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