Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hi everybody, please i need your help. i try to implement a sudoku game with success as you can See hier under:
/*
     * sudoku.cpp
     *
     */
 
<pre>
#include "sudoku.h"
#include &lt;string&gt;
using namespace std;
const char Sudoku::EMPTY_CELL = '0';
 
Sudoku::Sudoku()
{
    for (int row = 0; row &lt; SIZE; ++row)
    {
        for (int column = 0; column &lt; SIZE; ++column)
        {
            grid[row][column] = EMPTY_CELL;
        }
    }
}
 
bool
Sudoku::setGridPosition(int row, int column, char value)
{
    if (value == EMPTY_CELL)
    {
        grid[row][column] = value;
        return true;
    }
 
    for (int c = 0; c &lt; SIZE; ++c)
    {
        if (grid[row][c] == value)
            return false;
    }
 
for (int r = 0; r &lt; SIZE; ++r)
    {
        if (grid[r][column] == value)
            return false;
}
 
int brstart = row / 3 * 3; // note: integer division!
    int brend = brstart + 2;
int bcstart = column / 3 * 3; // note: integer division!
    int bcend = bcstart + 2;
    for (int br = brstart; br &lt;= brend; ++br)
        for (int bc = bcstart; bc &lt;= bcend; ++bc)
            if (grid[br][bc] == value)
                return false;
 
    grid[row][column] = value;
    return true;
}
 
bool
Sudoku::readStream(std::istream & input)
{
    for (int row = 0; row &lt; SIZE; ++row)
        if (!readLine(row, input))
            return false;
 
    return true;
}
 
bool
Sudoku::readLine(int row, std::istream & input)
{
string line;
    input &gt;&gt; line;
    if (line.length() &lt; 9)
        return false;
 
    for (int column = 0; column &lt; 9; ++column)
        setGridPosition(row, column, line[column]);
 
    return true;
}
 
void
Sudoku::solve()
{
    for (int row = 0; row &lt; Sudoku::SIZE; ++row)
{
        for (int column = 0; column &lt; Sudoku::SIZE; ++column)
        {
            if( grid[row][column] == Sudoku::EMPTY_CELL )
            {
                for (char value = '1'; value &lt;= '9'; ++value)
                {
                    if(setGridPosition(row, column, value))
                        break;
                }
            }
        }
    }
}
ostream &
operator &lt;&lt;(ostream & os, Sudoku & sudoku)
{
    string horizontalLine = "+-----------------------+";
 
    for (int row = 0; row &lt; Sudoku::SIZE; ++row)
    {
        if (row % 3 == 0)
            os &lt;&lt; horizontalLine &lt;&lt; endl;
        for (int column = 0; column &lt; Sudoku::SIZE; ++column)
        {
            if (column % 3 == 0)
                os &lt;&lt; "| ";
            os &lt;&lt; sudoku.readGridPosition(row, column) &lt;&lt; ' ';
        }
        os &lt;&lt; "|" &lt;&lt; endl;
    }
    os &lt;&lt; horizontalLine &lt;&lt; endl;
 
return os;

}
        /*
     * sudokuMain.cpp
     */
 
<pre>
#include "sudoku.h"
#include &lt;iostream&gt;
#include &lt;fstream&gt;
using namespace std;
 
int main(int argc, char * argv[])
{
    cout &lt;&lt; "Welcome to sudoku " &lt;&lt; endl;
 
    Sudoku sudoku;
 
    if( argc &gt; 1 )
 
    {
        fstream input(argv[1]);
        input &gt;&gt; sudoku;
    }
    else
        cin &gt;&gt; sudoku;
 
    sudoku.solve();
 
    cout &lt;&lt; sudoku;
 
    system("pause \n");
return 0;
}


I Create a new Project name "Project_Sudoku_Test" when i let my method empty the Programm run without problem but if i try to implement my method without success i get this failure "In german" <<error LNK2019: Verweis auf nicht aufgelöstes externes Symbol >>
in English i think it means error LNK2019: unresolved external
 
<h1>include "stdafx.h"</h1>
 
<h1>include "CppUnitTest.h"</h1>
 
using namespace std;
<h1>include "Sudoku.h"</h1>
 
<h1>include <fstream></h1>
 
<h1>include <iostream></h1>
 
<h1>include <string></h1>
 
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
 
namespace UnitTest1
{       
    TEST_CLASS(UnitTest1)
    {
    public:
 
<pre>
    TEST_METHOD(TestMethod1)
    {
    Sudoku sudoku ;//=  Sudoku();
     string expected =
         "+-----------------------+\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "+-----------------------+\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "+-----------------------+\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "| 0 0 0 | 0 0 0 | 0 0 0 |\n"
         "+-----------------------+\n"
         ;
        stringstream input;
        input &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl
            &lt;&lt; "000000000" &lt;&lt; endl;
 
        bool success = sudoku.readStream(input);
        Assert::IsTrue(success);
    }
 
};

}


that is the Failure error LNK2019: unresolved external
please cann you help me.
Thanks
Posted 21-Apr-13 2:46am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please have a look to:

http://msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx[^]

and check the correction and the relationship of your functions / classes...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 395
2 Maciej Los 285
3 ProgramFOX 265
4 CHill60 200


Advertise | Privacy | Mobile
Web01 | 2.8.150331.1 | Last Updated 21 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100