'get_call' 未在此范围内声明C++
'get_call' was not declared in this scope in C++
这是我第一次与C++合作。我已经在我的窗口机器中设置了日食CDT环境...我在下面写了代码,但不知何故,它让我在这样的方法上出错get_call -
'get_call' was not declared in this scope
下面是我的代码 -
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<string> data;
data.push_back("0");
data.push_back("1");
data.push_back("2");
get_call("1234", data);
return 0;
}
void get_call(string id, vector<string> data) {
for(std::vector<T>::reverse_iterator it = data.rbegin(); it != data.rend(); ++it) {
std::cout << *it;
}
}
我在上面的代码中做错了什么吗?
我正在Windows上使用eclipse CDT?
我的下一个问题是 - 一般来说,与C++合作的最佳方式是什么?我应该在VMWARE Player中使用Ubuntu VM来编译c ++项目,因为我发现很难让它在eclipse CDT中工作。
在调用函数之前,您需要转发声明get_call
函数。在C++符号使用之前需要知道它。
void get_call(string id, vector<string> data); // forward declare get_call function
int main() {
vector<string> data;
data.push_back("0");
data.push_back("1");
data.push_back("2");
get_call("1234", data);
return 0;
}
// function definition
void get_call(string id, vector<string> data) {
for(std::vector<string>::reverse_iterator it = data.rbegin(); // should be vector<strign>
it != data.rend(); ++it) {
std::cout << *it;
}
}
你写std::vector<T>::reverse_iterator
因为编译器不知道T
是什么,你应该使用vector<string>
将 get_call(( 放在 main(( 之前,或向前声明 get_call((。由于您使用的是Windows,Visual studio(VC++ express是免费的(很好,如果您想在没有Linux操作系统的情况下在Linux上运行代码,则可以使用cygwin,当然在VMWARE Player中工作可以让您在几乎真实的Linux操作系统中编程。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- 错误:未在此范围内声明'reverse'
- 并行用于C++17中数组索引范围内的循环
- 求出有多少个数字是完美平方,而sqrt()是L,R范围内的素数
- 不计算一个范围内的完美数
- 错误:"imread"未在此范围内声明
- 我在范围内未声明的错误类有问题
- 如何在cpp中使用地图显示给定日期范围内(在下面的问题中)的费率?
- 我有一个数组,我想输入一个范围,然后找到范围内所有偶数的总和?
- 未在此范围内声明错误 'xy'
- 在C++中使用变量而不是"#define"来指定数组大小是不是一种糟糕的做法?(C错误:在文件范围内
- 命名空间范围内的外部 - GCC vs clang vs msvc
- 如何改进一堆在已知值范围内评估变量的 else-if 条件?
- 如何仅使用 While 循环在给定范围内找到可被 7 整除的计数整数
- Socklen_t未在此范围内声明
- 错误:'[' 之前预期的非限定 id 和错误:'users'未在此范围内声明
- 查找给定范围内最长连续 1 的频率
- "Main"已在当前范围内声明
- c++ 变量在宏的扩展中没有在这个范围内声明
- 变量不在 lambda 的范围内