-7

I just want to prompt some integer from the user and pass it to the constructor function

Here's my class:

class queen {
 int N;
 int** queens;
 int *BFSq;
 int s;
 int front = 0;
 int rear = -1;
 int *found;

And here's my constructor:

public:
queen(){};
queen(int n)
{
    N=n;
    queens = new int*[n];
    for(int i = 0; i < n; ++i)
        queens[i] = new int[n];
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            queens[i][j]=0;
        }
    }
     BFSq = new int[n];
    found = new int[n];
}

And here is my main()function:

int main(){
int ent = 0;
cout<<"Please enter the size of your board\n";
cin>>ent;
queen(ent);
 }

I just want to pass ent value as int n argument to my constructor,but i think I'm not doing it right because I'm getting errors

EDIT: the error is "redefinition of 'ent' with a different type:'queen' vs 'int' "

pouyan021
  • 177
  • 1
  • 4
  • 19

1 Answers1

1

In main, queen(ent);, rather than creating a temporary queen using the constructor taking an int, tries to create a queen object called ent using the default constructor. Since ent already exists as an int the compiler throws an error. The solution is to create the object like this: queen q(ent);

Kevin
  • 6,993
  • 1
  • 15
  • 24
  • doesn't seems to work also `ent` in `queen(ent)` doesn't refer to an object and even the compiler knows it when you just type that function,it knows that it supposed to be an integer – pouyan021 Nov 13 '15 at 22:03
  • What is the error you're having then? I'm stuck using an older version of g++ at the moment so my error might not be the same as yours. Edit it into your question – Kevin Nov 13 '15 at 22:04
  • That's the same error as I had. Please replace `queen(ent);` with `queen q(ent);` and tell me if it fixes the issue – Kevin Nov 13 '15 at 22:07