C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-30-2003, 02:08 PM   #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
sentienttoaster is offline   Reply With Quote
Old 11-30-2003, 02:34 PM   #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 =)
gustavosserra is offline   Reply With Quote
Old 11-30-2003, 02:40 PM   #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
sentienttoaster is offline   Reply With Quote
Old 11-30-2003, 02:45 PM   #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 =)
gustavosserra is offline   Reply With Quote
Old 11-30-2003, 03:01 PM   #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
sentienttoaster is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking errors Zeeshan C++ Programming 1 02-22-2009 02:10 AM
HELP!!Why and How to solve this linking errors. huwan C++ Programming 3 05-07-2007 06:30 AM
new to visual C++ - "unresolved external symbol" linking errors ubermensch C++ Programming 8 04-27-2006 10:39 AM
Linking Errors ForlornOdium C++ Programming 1 12-07-2003 10:24 PM
Linking Errors... c++_n00b C++ Programming 9 06-08-2002 07:03 PM


All times are GMT -6. The time now is 02:50 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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