gpt4 book ai didi

c++ - 'get_call' 未在此范围内在 C++ 中声明

转载 作者:太空宇宙 更新时间:2023-11-04 14:00:54 24 4
gpt4 key购买 nike

这是我第一次使用 C++.. 我在我的 Windows 机器上设置了 eclipse 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>

关于c++ - 'get_call' 未在此范围内在 C++ 中声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19341405/

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