losing object type information

  • Thread starter Thread starter Jeroen Ceuppens
  • Start date Start date
J

Jeroen Ceuppens

Hi,

I want to write a function Cast() so I can use the if else if,... structure
everywhere in my program, but If I write a Cast() function, it must return
something, but how can you declare a funtion without knowing what the return
object type will be?

So public VOID Cast(LijstNode help) isn't possible, but if I change void to
LijstNode the Cast function will be useless (GetImageNode, ViewNode, ... are
derived from Lijstnode (is derived from TreeNode)), hope you can give me
some tips to fix this

Thx

See below the code.

private void buttonVoegToe_Click(object sender, System.EventArgs e)

{

LijstNode copy;

copy=(LijstNode)treeViewOverview.SelectedNode;

if ( copy is GetImageNode )

{

GetImageNode h = (GetImageNode)copy;

AddToLastNode(h);

}

else if ( copy is ViewNode )

{

ViewNode h = (ViewNode)copy;

AddToLastNode(h);

}

else if ( copy is CastNode )

{

CastNode h = (CastNode)copy;

AddToLastNode(h);

}

else if ( copy is FilterNode )

{

FilterNode h = (FilterNode)copy;

AddToLastNode(h);

}

else if ( copy is TimerNode )

{

TimerNode h = (TimerNode)copy;

AddToLastNode(h);

}

}
 
I'm confused, as casting is already available. You don't need to write a
function for casting. You can add/overload casting operators on your own
classes as well.

You can cast anything to an Object, if that's what you're trying to do, but
it seems to me that you really need to go through a tutorial or primer on
object-oriented program.

-Chris
 
Back
Top