davidx1
davidx1

Reputation: 3673

Why does the compiler tell me vector<string> is not declared?

I have some code here which reads from a file, and stores them in a vector.

I wish to pass this vector to another class. However, when i try to do that, it gives me a strange error, which i do not fully understand. It seems to be saying that the vector is not declared.

Here is the first few lines of a very long error:

 g++ C_Main.cpp C_HomePage.cpp C_SelectionPage.cpp -o Project
     C_HomePage.cpp:286:40: error: no ‘std::vector<std::basic_string<char> > HomePage::getDutiesList()’ member function declared in class ‘HomePage’
    C_HomePage.cpp:290:26: error: ‘std::vector<std::basic_string<char> > HomePage::getResourcesList’ is not a static member of ‘class HomePage’
    C_HomePage.cpp:290:26: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
    C_HomePage.cpp:291:2: error: expected primary-expression before ‘return’
    C_HomePage.cpp:291:2: error: expected ‘}’ before ‘return’
    C_HomePage.cpp:291:2: error: in C++98 ‘HomePage::getResourcesList’ must be initialized by constructor, not by ‘{...}’
    C_HomePage.cpp:291:2: error: no matching function for call to ‘std::vector<std::basic_string<char> >::vector(<brace-enclosed initializer list>)’

Here is line 282 - line 292 of C_HomePage.cpp

int HomePage::getInitPoints(){ 
    return initPoints; 
}

vector<string> HomePage::getDutiesList(){
    return dutiesList;
}

vector<string> HomePage::getResourcesList{
    return resourcesList;
}

Here is the corresponding declarations for those methods in H_HomePage.h

class HomePage {
        //These values will be the property of the flat
        //They are set before the login screen is displayed
        string manager;
        int initPoints;
        vector<string> dutiesList;
        vector<string> resourcesList;
        vector<FlatMember> flatMemberList;
        string loginName;


        public:

            HomePage(string);

            void login(string);
            string receivePassword();

            void importFlatMembers(string);
            void exportFlatMembers(string);         

            string getLoginName();
            string getManager();
            int getInitPoints();
            vector<string> getDutiesList;
            vector<string> getResourcesList;

};

I honestly does not know what is wrong, and have spent many hours getting frustrated over it already. Could someone please help?

Upvotes: 0

Views: 419

Answers (1)

Claw
Claw

Reputation: 767

You're missing parentheses in the declarations of getDutiesList and getResourcesList:

vector<string> getDutiesList();
vector<string> getResourcesList();

EDIT: You're also missing the parentheses in your .cpp file:

vector<string> HomePage::getResourcesList(){
    return resourcesList;
}

Upvotes: 1

Related Questions