Is it possible to make a generic overloaded operator in a class or interface?
[EDIT]It gives me an error now.
[/EDIT]Code:public static Cat<T> operator +(Cat<T> cat, Cat<T> cat2) { return (new Cat<T>(cat.name + cat2.name, 0, 1)); }
This is a discussion on Generic Operator Overloading within the C# Programming forums, part of the General Programming Boards category; Is it possible to make a generic overloaded operator in a class or interface? [EDIT]It gives me an error now. ...
Is it possible to make a generic overloaded operator in a class or interface?
[EDIT]It gives me an error now.
[/EDIT]Code:public static Cat<T> operator +(Cat<T> cat, Cat<T> cat2) { return (new Cat<T>(cat.name + cat2.name, 0, 1)); }
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Code:class Cat<T> { string name; T age; T weight; public Cat(string its_name, T its_age, T its_weight) { name = its_name; age = its_age; weight = its_weight; } public void Wash() { Console.WriteLine("Washed successfuly."); } public Cat<T> Marry(Cat<T> cat) { return (this + cat); } public static Cat<T> operator +(Cat<T> cat, Cat<T> cat2) { return (new Cat<T>(cat.name + cat2.name, 0, 1)); } public T Age { get { return age; } } public T Weight { get { return weight; } } public string Name { get { return name; } set { name = value; } } public override string ToString() { return "Cat Name: " + name; } public override bool Equals(object obj) { return base.Equals(obj); } public override int GetHashCode() { return base.GetHashCode() + age - weight; } ~Cat() { Console.WriteLine("{0} died.", name); } }
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C