linking errors

This is a discussion on linking errors within the C++ Programming forums, part of the General Programming Boards category; ok, here is my other program that I am having trouble with. It will look familiar. I have 2 linking ...

  1. #1
    Registered User sentienttoaster's Avatar
    Join Date
    Nov 2002
    Posts
    79

    linking errors

    ok, here is my other program that I am having trouble with. It will look familiar. I have 2 linking errors that I cannot figure out. I hope you can help.
    Code:
    #include <iostream>
    #include<ctime>
    using namespace std;
    
    void drawboard(int size, int sol);
    void AddQueen(int size, int row, int boards, int sol);
    
    int size;
    int col[];	                // column with the queen
    bool colfree[16];            // is the column free?  
    bool upfree[16];            //is the upward diagonal free?
    bool downfree[16];       	//is the downward diagonal free?
    
    
    int main()  //starts main
    {
    
     
    int row = -1;	//row whose queen is currently placed
    int boards = 0;		//number of positions investigated
    int sol = 0;	//number of solutions found
    
    	cout<<"What size board do you want?";
    	cin>>size;
      int i;
    
      for (i = 0; i < size; i++) colfree[i] = true;
    
      for (i = 0; i < size; i++) {
        upfree[i] = true;
        downfree[i] = true;
      }
    
      AddQueen(size, row, boards, sol);
    
    				//add function to print board and count # of times ran
    
      return 0;
    }
    
    					//AddQueen: attempt to place a queen
    void AddQueen(int size, int row, int boards, int sol)
    {					//AddQueen
      int c;		//column being tried for the queen
      float randnum;  //random number for placing if queen
      randnum=rand()%11;
      boards++;
      row++;
      for (c = 0; c < 8; c++)
        if (colfree[c] && upfree[row+c] && downfree[row-c+7]) {
          col[row] = c;	//put a queen in (row,c)
          colfree[c] = false;
          upfree[row+c] = false;
          downfree[row-c+7] = false;
          if (row == 7)		//end condition
            drawboard(size, sol);
          else
            AddQueen(size, row, sol, boards);		
          colfree[c] = true;	//now backtrack by removing the queen
          upfree[row+c] = true;
          downfree[row-c+7] = true;
        }
      row--;
    }
    
    //drawboard: print a solution
    void drawboard(int size, int sol) 
    {
        int i, j;
        sol++;
        cout << "board ran" << sol << " times" <<endl;
        cout << "-----------------" << endl;
        for (i = 0; i < 8; i++) {//for
            for (j = 0; j < col[i]; j++)
                cout << " -";
            cout << " Q";
            for (j++; j < 8; j++)
                cout << " -";
            cout << endl;
        }
        cout << "-----------------" << endl;
    }
    This has been a public service announcement from GOD.

    111 1111

  2. #2
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    And what are the error messages?
    Nothing more to tell about me...
    Happy day =)

  3. #3
    Registered User sentienttoaster's Avatar
    Join Date
    Nov 2002
    Posts
    79
    Linking...
    n queen.obj : error LNK2001: unresolved external symbol "int * col" (?col@@3PAHA)
    Debug/n queen1.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    n queen1.exe - 2 error(s), 0 warning(s)


    thems would be it
    This has been a public service announcement from GOD.

    111 1111

  4. #4
    Disturbed Boy gustavosserra's Avatar
    Join Date
    Apr 2003
    Posts
    244
    Again your compiler didnīt help you .
    The declaration of col array must have its size.

    Code:
    void drawboard(int size, int sol);
    void AddQueen(int size, int row, int boards, int sol);
    
    int size;
    int col[];	                // column with the queen
    bool colfree[16];            // is the column free?  
    bool upfree[16];            //is the upward diagonal free?
    bool downfree[16];
    Nothing more to tell about me...
    Happy day =)

  5. #5
    Registered User sentienttoaster's Avatar
    Join Date
    Nov 2002
    Posts
    79
    ok, that seemed to fix it. Thanks for now, I'm sure I will find trouble again
    This has been a public service announcement from GOD.

    111 1111

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking errors
    By Zeeshan in forum C++ Programming
    Replies: 1
    Last Post: 02-22-2009, 02:10 AM
  2. HELP!!Why and How to solve this linking errors.
    By huwan in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 07:30 AM
  3. Replies: 8
    Last Post: 04-27-2006, 11:39 AM
  4. Linking Errors
    By ForlornOdium in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2003, 10:24 PM
  5. Linking Errors...
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2002, 08:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21