0

Currently I'm getting a "declaration is incompatible" error in my code when trying to define a class member function that is using a 2d vector of a custom type as one of it's parameters. Here's a slimmed-down version of my class file that includes only the problem function:

#include <vector>
#include "sudoku_structs.cpp" //This is the file where I define my custom type called point

namespace std{
     class Square{
          private:
               bool checkCell(char num, int row, int col, vector<vector<point>> grid);
     };
}

Here's where I define my type in the sudoku_structs file:

typedef struct Point{
    char val;
    bool canModify, modified;
    Point();

} point;

Point::Point(){
    val = '0';
    canModify = false;
    modified = false;
}

And here's a slimmed-down version of my square_functions file that includes the problem line:

#include <vector>

#include "sudoku_structs.cpp"
#include "square_class.cpp" //Class file for the Square class that I showed previously

namespace std{
//Problem Line is the line Below
     bool Square::checkCell(char num, int row, int col, vector<vector<point>> grid){
          /*Cell-Checking Code*/
     }
}

Specifically, the error my compiler/vscode is giving is this:

declaration is incompatible with "bool std::Square::checkCell(char num, int row, int col, std::vector<std::vector<point, std::allocator>, std::allocator<std::vector<point, std::allocator>>> grid)" (declared at line 29)C/C++(147)

I'm actually in the processing of re-structuring working code, and this custom type is a part of the process. The function used to use a 2d vector of characters, rather than this custom type I'm using now, and it worked perfectly well. Therefore, I think the issue has got to be with either the namespace or how I define the point type and/or the Square member function, but I can't seem to find/come up with a solution that works, so any help would be greatly appreciated.

Also, if I haven't given enough code to get proper context/figure out the issue, please let me know, I'm new to the site and don't really know how much code I should/shouldn't be dumping here, and I would be happy to comment with more code, or link to a github page if needed.

bw2002
  • 1
  • 1
  • You shouldn't put code you write into namespace std. – doug Apr 07 '21 at 18:36
  • Unsure if related, but you should read this: https://stackoverflow.com/questions/1686204/why-should-i-not-include-cpp-files-and-instead-use-a-header – Woodford Apr 07 '21 at 18:50

0 Answers0