c++ - 变量 z 不能从不同的函数访问变量 x
问题描述
查看我提供的代码,我正在尝试使其 z = x
但它不起作用,因为 x 在不同的函数中。一直说 x 没有声明。有没有什么办法解决这一问题?
class game{
public:
void Starter(){
string z {"Test"};
z = x;
}
private:
void Questions(){
string x;
cout << "Welcome to this game, please answer with yes or no: \n \n";
解决方案
你需要传递x
给z
.
void Starter(string x){
string z {"Test"};
z = x;
}
然后在你的其他功能中你可以做Starter(x);
推荐阅读
- python - 在简单的 DRF API 中测试什么?
- django - 调用外键的主键并使用列表过滤器时,Django ORM 会命中数据库多少次?
- facebook - 如何获取访问令牌以将评论作者数据拉入 Integromat 以用于我拥有的 Facebook 群组中的帖子
- azure - 如何为 Get-AzureADUserAppRoleAssignment 创建循环?
- android - ClassNotFoundException: com.mysql.jdbc.Driver Error using Mysql and android
- r - 如何根据输入字符值命名新数据框
- mysql - 在没有-p的情况下使用my.ini从命令行访问mysql.exe?
- sql - 排除常见列的数据值
- javascript - 带有 HTML、Javascript 和 PHP 的动态表?
- java - 播放框架错误:未找到:值消息