Jump to content
  • Advertisement
Sign in to follow this  
steenreem

Can't get rid of silly warning in abstract class

This topic is 3661 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get the error 'Warning 1 Field 'MazeRunner.Number<Child>.Zero' is never assigned to, and will always have its default value '
    abstract class Number<Child> : Ordered<Child> where Child : Number<Child>
    {
        static Child Zero;   //ERROR IS HERE!
        public abstract Child Get();

        public bool IsPositive()
        {
            return (Get() >= Zero);
        }
    }

    class Int : Number<Int>
    {
        static Int Zero = new Int(0);
        int value;
        ..
    }

The field 'Zero' only has a value in Child classes. [Edited by - steenreem on September 15, 2008 7:13:45 AM]

Share this post


Link to post
Share on other sites
Advertisement
as DevFred points out, Number<Child>.Zero and Int.Zero are two different variables. The warning is legitimate. I'm also left wondering what the heck you've written a templated number class for.

Share this post


Link to post
Share on other sites
So.. I should make zero a method then?

Mr. Monkey, I was experimenting with templates and that's when I made the number class. The whole thing is here below. The templates get kinda crazy! =D


abstract class Equatable<Child> where Child : Equatable<Child>
{
public abstract bool Equals(Child c);

public static bool operator ==(Equatable<Child> f, Equatable<Child> s)
{
return (s.Equals((Child)f));
}
public static bool operator !=(Equatable<Child> f, Equatable<Child> s)
{
return !(s.Equals((Child)f));
}

public override int GetHashCode()
{
return base.GetHashCode();
}

public override bool Equals(System.Object s)
{
return base.Equals(s);
}
}

abstract class Ordered<Child> : Equatable<Child> where Child : Ordered<Child>
{
abstract public bool Smaller(Child s);
public static bool operator <(Ordered<Child> f, Ordered<Child> s)
{
return (f.Smaller((Child)s));
}
public static bool operator >(Ordered<Child> f, Ordered<Child> s)
{
return (s.Smaller((Child)f));
}
public static bool operator >=(Ordered<Child> f, Ordered<Child> s)
{
return (s.Smaller((Child)f) || s.Equals((Child)f));
}
public static bool operator <=(Ordered<Child> f, Ordered<Child> s)
{
return (f.Smaller((Child)s) || s.Equals((Child)f));
}

public override bool Equals(Child s)
{
return ((this < s) && (this > s));
}

public override int GetHashCode()
{
return base.GetHashCode();
}
}

abstract class Number<Child> : Ordered<Child> where Child : Number<Child>
{
static Child Zero;
public abstract Child Get();

public bool IsPositive()
{
return (Get() >= Zero);
}

abstract public Child Divide(Child f);

public static Child operator /(Number<Child> f, Child s)
{
return f.Divide(s);
}

}

class Int : Number<Int>
{
static Int Zero = new Int(0);
int value;

public Int Random(Int i)
{
Random r = new Random();
return r.Next(this, i);
}

public override Int Get(){return this;}

public override bool Equals(Int s)
{
return value == s;
}

public override bool Smaller(Int s)
{
return value < s;
}

public static implicit operator int(Int I)
{
return I.value;
}

public static implicit operator Int(int i)
{
return new Int(i);
}

public Int(int boot)
{
value = boot;
}

public override Int Divide(Int s)
{
return new Int(this/s);
}

public Int Half()
{
return (this / 2);
}

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!