0

I have a code like this:

class oBT{
    public: void clean(int**);
            void write(int**);
            bool check(int**);
            void backtrack(int**,int);
};

void oBT::clean(int R[8][8])
{ for(int i=1; i<=8; i++) for(int j=1; j<=8; j++) R[i][j]=0; }

void oBT::write(int R[8])
{
    for(int i=1; i<=8; i++)
    {
        for(int j=1; j<=8; j++)
            std::cout<<R[i]<<' ';
        std::cout<<'\n';
    }
    std::cout<<'\n';
}

bool oBT::check(int R[8], int i=1)
{
    for(int j=1; j<=8; j++)
    {
        for(int k=1; k<=8; k++)
        {
            if(R[i]==R[j]) return false;
            if(R[j]==R[j]) return false;
        }
        i++;
    }
    return true;
}

void oBT::backtrack(int R[8], int i=1)
{
    for(int j=1; j<=8; j++)
        for(int k=1; k<=8; k++)
        {
            R[j]=1;
            if(check(R))
                if(i<8) backtrack(R,i+1);
                else { write(R); clean(R); }
        }
}

and when I try to compile it, I get the following error:

C:\OJI\Eight Queen Puzzle\Class.h|8|error: prototype for 'void oBT::clean(int (*)[8])' does not match any in class 'oBT'|
C:\OJI\Eight Queen Puzzle\Class.h|2|error: candidate is: void oBT::clean(int**)|
C:\OJI\Eight Queen Puzzle\Class.h|11|error: prototype for 'void oBT::write(int*)' does not match any in class 'oBT'|
C:\OJI\Eight Queen Puzzle\Class.h|3|error: candidate is: void oBT::write(int**)|
C:\OJI\Eight Queen Puzzle\Class.h|22|error: prototype for 'bool oBT::check(int*, int)' does not match any in class 'oBT'|
C:\OJI\Eight Queen Puzzle\Class.h|4|error: candidate is: bool oBT::check(int**)|
C:\OJI\Eight Queen Puzzle\Class.h|36|error: prototype for 'void oBT::backtrack(int*, int)' does not match any in class 'oBT'|
C:\OJI\Eight Queen Puzzle\Class.h|5|error: candidate is: void oBT::backtrack(int**, int)|

||=== Build finished: 8 errors, x warnings ===|

1 Answer 1

3

Arrays are not pointers, and pointers are not arrays. If you want to pass in multidimensional arrays, either use double pointers and dynamic memory allocation (i. e. new), or declare your functions to accept an array of arrays, like

void clean(int parm[8][8]);

etc.

Also, your check function has a 'typo', you omitted the 'size' argument from the prototype; instead of

bool check(int **);

it should be

bool check(int R[8][8], int i);
Sign up to request clarification or add additional context in comments.

2 Comments

@UrecheVlad You're welcome. I'd suggest you read a paper on C pointers and arrays. You can also accept my answer if it helped, thanks.
I know my way around pointers and arrays, but I'm new to classes and function prototypes. I'm going to read into it further. Again, thanks a lot for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.