繁体   English   中英

代码无法识别“ #include”语句

[英]Code not recognizing “#include” statements

我正在为项目编写一些头文件,但是由于某种原因,我会收到错误消息“ Identifier''undefined。我在做什么错?(它不能将字符串或布尔值识别为正确的)

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

布尔型实际上是在c++键入为bool 。此外,它无法识别字符串的原因是stringstd namespace一部分using namespace std; 在您的include下,否则您需要将string作为std::string地址。std std namespace中的其他元素是Vector,List等。您可以在这里查看这些元素

编辑:还我刚刚注意到您的getter / setter方法。使用了getter方法,因此您可以在不公开对象属性的情况下访问对象属性,它返回该属性的类型。如果要访问描述为std::string的名称,方法应该返回std::string意味着您的2个getter应该看起来像这样:

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

由于LF指出,这是不使用的命名空间很好的做法,因为它可能会导致混乱,甚至相互冲突的code.The引用是这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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