CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: TicTacToe

  1. #1
    Join Date
    Nov 2011
    Posts
    2

    TicTacToe

    Constantly getting the same errors, but unable to fix it! Please help.

    part of my .cpp file
    [/code]
    int TTT::getMatSum()
    {
    if ((matSum(matrix , 3))==90)
    return 1;
    else
    return 0;
    }
    [code]

    The error code I'm getting is:

    erroe C2664 TTT:matSum' : cannot convert parameter 1 from 'int[3][3] to int [][3]

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: TicTacToe

    That's hard to tell knowing neither the declaration/definition of matSum() nor matrix.

    Also, the fact that matrix obviously is a native array (can be concluded from the error message, not the spartanic code snippet) suggests that your program as a whole is native C++. In this case you posted in the wrong forum section. This is the right one: http://www.codeguru.com/forum/forumdisplay.php?f=9

    BTW, your code tags are reversed: [/code] is the closing tag, not the opening one.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Nov 2011
    Posts
    2

    Re: TicTacToe

    its Visual, and the other one states non visual.

    Thanks for your reply, I now better understand the error. I have another question which would help me a lot.

    I was taught a while back that arrays are like follows:

    name[3][3];

    if I had a variable for exampe size = 3; and I wanted to use it I could do:
    name[][size];

    now in cli its different, so i set up an array like this:

    array <int,2>^ name;
    name=gcnew array <int,2>(3,3);

    But how would I input a size into this?
    would it be:

    name(,size);

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: TicTacToe

    Quote Originally Posted by kinggrunt View Post
    its Visual, and the other one states non visual.
    Well, admittedly the focus of the three main native C++ forum sections isn't completely obvious from just their title, and even the short description doesn't always clear all uncertainties. This is what they're about:
    • Visual C++: actually Visual C++ together with the MS frameworks MFC/ATL.
    • Non Visual C++: actually non visual C++ specific. I.e. questions about standard C++ belong there, even if you're using Visual C++ for your program.
    • C++ and Win API: Windows programming in native C++ without using the frameworks discussed in the Visual C++ section (or rather any framework, mostly raw Win32 API coding there), regardless of what compiler/IDE (including VC++!) you're using.


    I was taught a while back that arrays are like follows:

    name[3][3];

    if I had a variable for exampe size = 3; and I wanted to use it I could do:
    name[][size];
    That's correct for native C++, but in C++/CLI, as you're describing later on in your post (which BTW now clarifies that you posted in the perfectly correct section), not only the declaration and instantiation of the managed arrays are different, but also the way you pass them to functions as parameters.

    now in cli its different, so i set up an array like this:

    array <int,2>^ name;
    name=gcnew array <int,2>(3,3);

    But how would I input a size into this?
    would it be:

    name(,size);
    You already got declaration and instantiation of the array right, but, as already mentioned, the way you access the indiidual array items or pass such an array as a function parameter is different from native C++ as well, both in declaring/defining the function and calling it.

    Here's a small demo of passing a 2D managed array to a function:

    Code:
    // Test5.cpp: Hauptprojektdatei.
    
    #include "stdafx.h"
    
    using namespace System;
    
    void f(array<int, 2> ^an)
    {
      for (int i = 0; i < an->GetLength(0); ++i) {
        for (int j = 0; j < an->GetLength(1); ++j)
          Console::Write("{0} ", an[i, j]);
        Console::WriteLine();
      }
    }
    
    int main(array<System::String ^> ^args)
    {
      array<int, 2> ^an = gcnew array<int, 2>(3, 3);
      for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; ++j)
          an[i, j] = i * j;
      f(an);
    
    #ifdef _DEBUG
      Console::WriteLine("Hit <Enter> to continue...");
      Console::ReadLine();
    #endif
      return 0;
    }
    For reference on managedarrays see http://msdn.microsoft.com/en-us/library/ts4c4dw6.aspx including its subtopics, especially http://msdn.microsoft.com/en-us/library/2xfh4c7d.aspx, as well as http://msdn.microsoft.com/en-us/libr...tem.array.aspx.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured