gpt4 book ai didi

C++ 我不断收到 "was not declared in this scope error"

转载 作者:搜寻专家 更新时间:2023-10-30 23:52:21 24 4
gpt4 key购买 nike

所以,我有一个头文件和一个类文件。但是当我编译 puzzle.cpp 时,我总是得到 get_solution was not declared in this scope。我不明白为什么会发生该错误,因为它在同一个类中,所以我可以在同一个类中调用任何函数。谁能帮我解决这个问题?谢谢!

puzzle.h

#ifndef PUZZLE_H
#define PUZZLE_H

#include<iostream>
#include <string>
#include <vector>

class puzzle{
private:
std::string _solution;
std::vector<bool> _guesses;
public:
puzzle(std::string solution);
std::string get_solution(){return _solution;}
bool guess(char c);
bool solve(std::string proposed_solution);
std::string to_string();
};

#endif

拼图.cpp

#include <iostream>
#include "puzzle.h"
#include <string>
#include <vector>

using namespace std;

puzzle::puzzle(std::string solution) {
_solution = solution;
for(int i = 0; i < 256; i++)
_guesses.push_back(false);
}

bool puzzle::guess(char c){
int num = c;
if(c<='z' || c>='a')
if(_guesses.at(c) == false){
_guesses.at(c) == true;
return true;
}
return false;
}

bool solve(string proposed_solution){
string test = get_solution();
if(proposed_solution.compare(test) == 0)
return true;
return false;
}

string to_string(){
int len = get_solution().length();
return "";
}

最佳答案

看起来你忘了制作 solveto_string 成员函数:

改变

string to_string(){ ...
bool solve(string proposed_solution){ ...
^^^

string puzzle::to_string(){ ...
bool puzzle::solve(string proposed_solution){ ...

关于C++ 我不断收到 "was not declared in this scope error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48672345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com