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

'get_call' was not declared in this scope in C++

本文关键字:范围内 C++ 声明 call get      更新时间:2023-10-16

这是我第一次与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操作系统中编程。