我在代码中添加了一个新的源代码文件夹,并创建了一个具有以下标题和cpp文件的新类。
#ifndef ENVIRONMENT_H_
#define ENVIRONMENT_H_
#include <string.h>
using namespace std;
namespace daemonWorld {
class Environment {
const string objName;
public:
Environment(const string & name){
this->objName = name;
}
virtual ~Environment();
};
} /* namespace daemonWorld */
#endif /* TEMP_ENVIRONMENT_H_ */CPP文件
#include "Environment.h"
namespace daemonWorld {
Environment::~Environment() {
// TODO Auto-generated destructor stub
}
} /* namespace daemonWorld */我收到一个错误,string不是构造函数和成员变量Obj中的类型,我在cpp文件成员声明中得到了Codan错误,构造函数找不到。我已经多次清理项目,重建索引和重建项目,但它不起作用。知道吗?
发布于 2015-10-21 22:43:01
#include <string.h>应该是
#include <string>string.h是C字符串头。string是C++字符串头。
此外,所有标准的C++标头都省略了.h。即使是从C++代码中包含的C头,除了省略.h之外,也应该以c作为前缀。例如,cstring将是用于在C++中获取C字符串头的正确的标头。
https://stackoverflow.com/questions/33270448
复制相似问题