简体   繁体   中英

Code not recognizing “#include” statements

I'm writing some header files for a project, but for whatever reason, I'm getting the error "Identifier ' ' is undefined. What am I doing wrong? (It won't recognize string or Boolean as correct)

#include <iomanip>
#include <iostream>
#include <string>

class Camper {
private:
    string name;
    boolean paid;
public:
    void setName(string);
    void getName() const;

    void setPaid(boolean);
    void getPaid() const;

    void display() const;
};

Booleans are actually typed as bool in c++ .Also the reason it wont recognize string is that string is part of the std namespace .You either need to add using namespace std; under your includes,or else you need to adress string as std::string .Some more elements from the std namespace are Vector,List,etc.You can take a look at those here

EDIT:Also I just noticed your getter/setter methods.A getter method is used so you can access Object attributes without them being public,it returns a type of that attribute.If you want to access name described as an std::string your method should return std::string .Meaning your 2 getters should look like this:

bool getPaid() const;
std::string getName() const;

As LF pointed out it is not good practice to use namespaces as it can lead to confusing or even conflicting code.The reference is this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM