c++ - 如何以自定义类型的二维向量作为参数正确定义类成员函数?(C++)
问题描述
目前,当我尝试定义一个使用自定义类型的二维向量作为其参数之一的类成员函数时,我的代码中出现“声明不兼容”错误。这是我的类文件的精简版本,仅包含问题函数:
#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);
};
}
这是我在 sudoku_structs 文件中定义我的类型的地方:
typedef struct Point{
char val;
bool canModify, modified;
Point();
} point;
Point::Point(){
val = '0';
canModify = false;
modified = false;
}
这是我的 square_functions 文件的精简版本,其中包含问题行:
#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*/
}
}
具体来说,我的编译器/vscode 给出的错误是:
声明与“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)"(在第 29 行声明)C/C++(147)
我实际上正在处理重构工作代码,而这种自定义类型是该过程的一部分。该函数用于使用 2d 字符向量,而不是我现在使用的这种自定义类型,并且效果非常好。因此,我认为问题必须与命名空间或我如何定义点类型和/或 Square 成员函数有关,但我似乎无法找到/想出一个有效的解决方案,所以任何帮助都会不胜感激。
另外,如果我没有提供足够的代码来获取正确的上下文/找出问题,请告诉我,我是该网站的新手,我真的不知道我应该/不应该在这里倾倒多少代码,如果需要,我很乐意用更多代码发表评论,或者链接到 github 页面。
解决方案
推荐阅读
- arrays - for 循环的迭代次数
- python - 如何使用 re.sub 专门删除带有类的标签
- swift - 如何将 UIMenu 方向更改为 RTL
- python - 将元组转换为列表的时间复杂度(反之亦然)
- reactjs - 当我的函数检查它是否未定义时,为什么打字稿会抱怨该变量可能未定义?
- android - 如何将数据从 Android 服务发送到其 AIDL 存根
- javascript - 导航菜单到汉堡菜单
- actions-on-google - 您可以从语音识别平台(如 Amazon Alexa 或 Google Assistant)中检索语音记录吗?
- javascript - 在延迟显示的 JavaScript 循环中更改背景颜色
- reactjs - 带有 React Hook 表单的 EmailJS REST API