理解范围的问题
Problems with understanding scope
i | m在了解类或功能的范围时遇到问题。这个程序是不完整的,但是我无法在同一类中,然后在其他类中使用功能。例如:我遇到一个错误,说
"在此范围中没有声明'selector'
您能帮我弄清楚怎么了吗?谢谢
#include <iostream>
using namespace std;
int main(void){
selector();
}
void selector(){
linkedList test;
/* block of code */
}
class linkedList{
Node *head;
public:
linkedList(){
head = NULL;
}
//other lines
};
class Node{
public:
int data;
Node * next;
}
我不明白您为什么要谈论类,但是函数的范围是从其声明到文件末尾。只需在您的代码中交换两个函数:
void selector() {
// linkedList test;
/* block of code */
}
int main() {
selector(); // selector is in scope here
}
(我不确定您为什么要做int main(void)
。这更多是C事物。没有参数的C 功能看起来像int main()
。)
相关文章:
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- 我在范围内未声明的错误类有问题
- 如何在cpp中使用地图显示给定日期范围内(在下面的问题中)的费率?
- 使用基于范围的循环迭代矢量时出现问题
- 示例代码中使用分隔符将 std::string 拆分为 std::vector 的范围问题
- C++ 字符串订阅超出范围的问题
- 命名空间范围问题
- 无法取消引用超出范围的向量迭代器 - 有什么问题?
- 断言失败错误,C++中的矢量下标超出范围问题
- 给定数组范围的选择排序问题
- 指针范围问题和返回类中封装的指针向量内的指针引用
- C++范围?将数组传递给函数时出现问题
- C++奇怪的问题.数据成员超出范围
- PlatformIO 的范围问题(?)
- C++. 面试. 关于返回 int* 值问题的范围
- 编程:原理与实践 使用C++ 第 4 章演练步骤 6:关于数字范围的一般问题
- 为什么BKDFHash不关心超出范围的问题?
- 访问函数中的使用声明:与范围相关的问题
- 函数返回本地变量,尽管变量不超出范围,没有编译器问题,并且代码执行
- 无法编译 - 范围问题