0
#include <iostream>
    #include <fstream>
    #include <algorithm>
    #include <string>

    using namespace std;

    // global constant and variables
    const string INFILENAME = "sudokutest.txt";
    const char   PRE_NUM1   = '9';
    const char   PRE_NUM2   = '8';
    const char   PRE_NUM3   = '7';
    const char   HELP_NUM   = 'A';
    const char   POS_NUM1   = '7';
    const char   POS_NUM2   = '9';
    const char   POS_NUM3   = '8';

    char     table1[9][9];           // sudoku table start
    char     table2[9][9];           // sudoku table finish

    // fuction prototypes
    void swap(string& buf, char& value);
    void loadTable(char table[][9]);
    void printTable(char table[][9]);

    int main()
    {
        loadTable(table1);    // load tables
        cout << "      Start      " << endl;
        printTable(table1);   // display table1 
        cout << endl;
        cout << "      Finish      " << endl;
        printTable(table2);   // display table2

        return 0;
    }


    /* 1
    Function       : swap the numbers stated in constants
    Precondition   : none
    Postcondition  : table1 and table2 are load using the swaped numbers
    Comment        : using 'A' to avoide duplication of swap
    */

    //swap
    void swap(string& buf, char& value)
    {
        string s = buf;

        replace(s.begin(), s.end(), PRE_NUM1, HELP_NUM);
        replace(s.begin(), s.end(), PRE_NUM2, POS_NUM2);
        replace(s.begin(), s.end(), PRE_NUM3, POS_NUM3);
        replace(s.begin(), s.end(), HELP_NUM, POS_NUM1);

        value = s.at(0);
    }



The program works as intended but I want to try using the swap method. I've tried just putting inside of main but it said something about being overloaded. I can't figure out if I'm missing a prereq or I'm doing something wrong. Any help or comment is appreciated.

Gadtu
  • 1
  • 2
  • 1
    please include the exact error message – pm100 Feb 25 '23 at 00:55
  • and is the code above the one that works or the one that fails? It uses replace inside its swap function – pm100 Feb 25 '23 at 00:57
  • the error message was cannot determine which instance of overloaded function swap is intended the code above works but it's just a segment of the full code, the method is called swap but it's not using any swap methods – Gadtu Feb 25 '23 at 01:00
  • 2
    please post the code that fails , and include the full error message (paste it into the question) – pm100 Feb 25 '23 at 01:05
  • 2
    Drop `using namespace std;`, then your `swap` won't conflict with `std::swap` defined in the C++ standard library. `using namespace std;` is considered poor form for this very reason, the reason that you learned the hard way. – Igor Tandetnik Feb 25 '23 at 01:17
  • Whatever learning resource it was that convinced you that `using namespace std;` was a good idea was playing a cruel trick on you. [These are the symbols you can't use freely](https://en.cppreference.com/w/cpp/symbol_index) because of that one line. – Drew Dormann Feb 25 '23 at 01:54

0 Answers0