I added a new source folder to my code and create a new class with below header and cpp file
#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 file
#include "Environment.h"
namespace daemonWorld {
Environment::~Environment() {
// TODO Auto-generated destructor stub
}
} /* namespace daemonWorld */
I am getting an error that string is not a type in constructor and the member variable Obj and I am getting Codan error in cpp file Member declaration not found for constructor. I have many times cleaned the project, rebuild the index and rebuild the project but it doesn't work. Any Idea?
#include <string.h>
should be
#include <string>
string.h
is the C string header. string
is the C++ string header.
Furthermore, all standard C++ headers omit the .h
. Even the C headers, when included from C++ code should be prefixed with c
in addition to omitting the .h
. E.g. cstring
would be the correct header to include to get the C string header in C++.