Search code examples
c++vectoreclipse-cdt

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


This is my first time working with C++.. And I have setup eclipse CDT environment in my windows machine... And I wrote below code but somehow, it is giving me an error on get_call method like this -

'get_call' was not declared in this scope

Below is my code -

#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;
    }
}

Is there anything wrong I am doing in my above code?

I am working with eclipse CDT on windows?

And my next question is - In general what's the best way to work with C++? Should I use Ubuntu VM in VMWARE Player to compile c++ project as I am finding very hard time making it work in eclipse CDT..


Solution

  • You need to forward declare get_call function before call it. In C++ a symbol needs to be known before it's used.

    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;
        }
    }
    

    You wrote std::vector<T>::reverse_iterator as compiler has no idea what T is, you should use vector<string>