问题描述
嗨
- 我有一个Node类,它有一个子类Num,它继承自Node。
- 我有一个函数Evaluate ;这需要两个节点作为参数。
- 我通过发送两个Num来调用此函数。当我使用
GetType()。ToSTring()时,它似乎意识到它收到的参数
实际上是Nums,而不是节点。
- 如何将参数转换为Nums以便我可以使用所有成员函数
和变量,而无需手动执行
,即( NUM)someVariable。我想这样做,所以我可以发送评估
许多不同的Node子,而不会使每个添加的代码进一步复杂化
。我无法弄清楚怎么做
GetType()。
帮助大多数人赞赏。
干杯
dave
hi
- I have a class Node, with a child class Num, that inherits from Node.
- I have a function "Evaluate" that takes two Nodes as an argument.
- I call this function by sending it two "Num"''s. When i use
GetType().ToSTring(), it seems to be aware that the arguments it recieved
are in fact Nums, not Nodes.
- How do I cast the arguments to Nums so I can use all the member functions
and variables, without doing
it manually, ie (Num)someVariable. I want to do this so I can send Evaluate
lots of different childs of Node, without having complicate
my code further for each addition. I can''t figure out how to do it with
GetType().
Help most appreciated.
Cheers
dave
推荐答案
这篇关于使用GetType进行类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!