Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,789 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,315 people online right now. Registration is fast and FREE... Join Now!




weird error

 
Reply to this topicStart new topic

weird error

SleepingOlive
2 Oct, 2008 - 06:44 AM
Post #1

New D.I.C Head
*

Joined: 16 Sep, 2008
Posts: 20



Thanked: 1 times
My Contributions
My error says that type powers already defines a member called 'op_ExclusiveOr' with the same parameter types?????
any help


CODE

using System;

class Powers
{
    public int x;//, y, z;
    
    public Powers(int x)//, int y, int z);
    {
        this.x = x;
        //this.y = y;
        //this.z = z;
    }
    
    public Powers(Powers rhs)
    {
        x = rhs.x;
        //y = rhs.y;
        //z = rhs.z;
    }
    
    public override string ToString()
    {
        return "( " + x + " )";//, " + y + ", " + z + " )";
    }
    
    public static Powers operator ^ (Powers lhs, Powers rhs)
    {
        Powers result = new Powers(lhs);
        result.x = rhs.x * rhs.x * rhs.x;
        //result.y = rhs.y * rhs.y * rhs.y;
        //result.z = rhs.z * rhs.z * rhs.z;
        return result;
    }
    
    //public static Powers operator ^ (Powers lhs, Powers rhs)
    //{
     //   return new Powers(lhs * rhs.x);
    //}
    
    public static double operator ^ (Powers lhs, Powers rhs)
    {
        return lhs.x * rhs.x;
    }
} //END CLASS POWER

class RaisePower
{
    public static void Main(string[] args)
    {
        Powers p1, p2, p3;
        p1 = new Powers(3);
        p2 = new Powers(3);
        p3 = p1 ^ p2;
        
        result = p1 ^ p2;
        Console.WriteLine("p1 = " + p1.ToString());
    }
}


User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Weird Error
2 Oct, 2008 - 06:53 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
That's because you're overloading ^ two times with the same signature

csharp

public static Powers operator ^ (Powers lhs, Powers rhs)
{
Powers result = new Powers(lhs);
result.x = rhs.x * rhs.x * rhs.x;
//result.y = rhs.y * rhs.y * rhs.y;
//result.z = rhs.z * rhs.z * rhs.z;
return result;
}

public static double operator ^ (Powers lhs, Powers rhs)
{
return lhs.x * rhs.x;
}

User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Weird Error
2 Oct, 2008 - 11:06 AM
Post #3

D.I.C Regular
Group Icon

Joined: 21 Mar, 2008
Posts: 374



Thanked: 19 times
Dream Kudos: 25
My Contributions
it's not that weird of an error....since you posted about it yesterday

http://www.dreamincode.net/forums/showtopic65720.htm

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 01:32PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month