J
Jeremy
C++ guy here. Why can't I do this?
class A
{
public int member = 0;
}
class B : A
{
}
class Form
{
void Main()
{
B ObjB = new B();
DoSomethingWithMember(ref B); <------ This won't compile
}
void DoSomethingWithMember(ref A)
{
A.member++;
}
}
Error is:
error CS1503: Argument '1': cannot convert from 'ref B' to 'ref A''
How am I supposed to use polymorphic types if I can't chuck objects
around by referencing their base?
Cheers,
Jeremy
class A
{
public int member = 0;
}
class B : A
{
}
class Form
{
void Main()
{
B ObjB = new B();
DoSomethingWithMember(ref B); <------ This won't compile
}
void DoSomethingWithMember(ref A)
{
A.member++;
}
}
Error is:
error CS1503: Argument '1': cannot convert from 'ref B' to 'ref A''
How am I supposed to use polymorphic types if I can't chuck objects
around by referencing their base?
Cheers,
Jeremy