Click here to Skip to main content
15,902,275 members
Home / Discussions / C#
   

C#

 
AnswerRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 4:59
[Marc]1-Nov-05 4:59 
GeneralRe: Class Objects and Equals Operator Pin
budidharma1-Nov-05 5:21
budidharma1-Nov-05 5:21 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 6:27
[Marc]1-Nov-05 6:27 
GeneralRe: Class Objects and Equals Operator Pin
budidharma1-Nov-05 7:23
budidharma1-Nov-05 7:23 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 9:28
[Marc]1-Nov-05 9:28 
GeneralRe: Class Objects and Equals Operator Pin
budidharma1-Nov-05 14:36
budidharma1-Nov-05 14:36 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]1-Nov-05 17:33
[Marc]1-Nov-05 17:33 
GeneralRe: Class Objects and Equals Operator Pin
budidharma2-Nov-05 2:00
budidharma2-Nov-05 2:00 
God, I must be really annoying by now ... but I'm having some problem i can't seem to find. I'm sure I'm overlooking something stupid.

... relevant methods from the card class ...

<br />
        public Card(Card c)<br />
        {<br />
            m_Rank = c.GetRank();<br />
            m_Suit = c.GetSuit();<br />
        }<br />
<br />
        public object Clone()<br />
        {<br />
            return new Card(this);<br />
        }<br />


... relevant methods from the deck class ...

<br />
        public void Shuffle()<br />
        {<br />
            Random rand = new Random();<br />
<br />
            for (int i = 0; i < 52; i++)<br />
            {<br />
                int first = rand.Next(52);<br />
                int second = rand.Next(52);<br />
<br />
                // Copy data from random card 1 to tempcard<br />
                // Copy data from random card 2 to card 1<br />
                // Copy data from tempcard to card 2<br />
                Card tempCard = m_Deck[first].Clone();<br />
                m_Deck[first] = m_Deck[second].Clone();<br />
                m_Deck[second] = tempCard.Clone();<br />
            }<br />
<br />
        }<br />


... Throws the error:
Error 4 Cannot implicitly convert type 'object' to 'Poker.Card'. An explicit conversion exists (are you missing a cast?) C:\...\Cards.cs 246 33 Poker


I tried to fix it myself, can't seem to figure out where the problem is.
When I call clone, it creates a new object from this and returns it cast as a card. I thought I'd be able to simply set an object equal to that new object ... apparently not though.

I also tried:
Card c = new mycard.Clone(); ... that throws an error as well.

Sorry for so many questions. Thank you for all the help.
GeneralRe: Class Objects and Equals Operator Pin
budidharma2-Nov-05 2:04
budidharma2-Nov-05 2:04 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]3-Nov-05 0:56
[Marc]3-Nov-05 0:56 
GeneralRe: Class Objects and Equals Operator Pin
Febret1-Nov-05 6:39
Febret1-Nov-05 6:39 
AnswerRe: Class Objects and Equals Operator Pin
S. Senthil Kumar1-Nov-05 19:15
S. Senthil Kumar1-Nov-05 19:15 
GeneralRe: Class Objects and Equals Operator Pin
[Marc]3-Nov-05 1:24
[Marc]3-Nov-05 1:24 
QuestionGetting Enum Type from Value Pin
budidharma1-Nov-05 3:10
budidharma1-Nov-05 3:10 
AnswerRe: Getting Enum Type from Value Pin
Libor Tinka1-Nov-05 3:20
Libor Tinka1-Nov-05 3:20 
AnswerRe: Getting Enum Type from Value Pin
S. Senthil Kumar1-Nov-05 3:22
S. Senthil Kumar1-Nov-05 3:22 
GeneralRe: Getting Enum Type from Value Pin
budidharma1-Nov-05 4:30
budidharma1-Nov-05 4:30 
Questionhow to display brokenrule in a messagebox with yes no button. Yes means continue with brokenRule Pin
lokeshkumble1-Nov-05 2:52
lokeshkumble1-Nov-05 2:52 
AnswerRe: how to display brokenrule in a messagebox with yes no button. Yes means continue with brokenRule Pin
J4amieC1-Nov-05 4:11
J4amieC1-Nov-05 4:11 
GeneralRe: how to display brokenrule in a messagebox with yes no button. Yes means continue with brokenRule Pin
lokeshkumble1-Nov-05 21:14
lokeshkumble1-Nov-05 21:14 
QuestionSystem.Data.Odbc Pin
zaboboa1-Nov-05 2:41
zaboboa1-Nov-05 2:41 
AnswerRe: System.Data.Odbc Pin
S. Senthil Kumar1-Nov-05 3:28
S. Senthil Kumar1-Nov-05 3:28 
GeneralRe: System.Data.Odbc Pin
zaboboa1-Nov-05 3:40
zaboboa1-Nov-05 3:40 
Questiondisplay program file in window form Pin
hongweng1-Nov-05 2:16
hongweng1-Nov-05 2:16 
AnswerRe: display program file in window form Pin
Judah Gabriel Himango1-Nov-05 4:58
sponsorJudah Gabriel Himango1-Nov-05 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.