Sign in to follow this  
steenreem

Latest Child Type

Recommended Posts

Hello. I have a class which I'm primarily using to derive from. Is there some keyword which refers to the last type that inherited from the current class. like:
    class foo
    {
        int i1;

        LatestChild sum(LatestChild c1, LatestChild c2)
        {
            return (LatestChild)(new foo(c1 + c2)); //assuming the conversion goes ok.
        }
    }
atm I have code like this:

    class Vector<ElementType> : Clonable where ElementType : Number<ElementType>
    {
        protected int dimensions;
        protected ElementType[] cors;

        public static Vector<ElementType> operator /(Vector<ElementType> v, ElementType i)
        {
            for (Enumerator<ElementType> e = new Enumerator<ElementType>(ref v.cors); e.MoveNext();)
            {
                e.Current /= i;
            }
            return v;
        }

    }

//This part is very trivial and I'd like a way so that I don't have to type this.
class IntVector3d : Vector3d<Int>
    {
        public static IntVector3d operator /(IntVector3d v, Int i)
        {
            return (IntVector3d)((Vector<Int>)v / i);
        }
    }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this