I have this 2 separated class and i cant fix this compiler problem:
In file included from classA.cpp:2:0: classB.h:6:10: error: 'string' in namespace 'std' does not name a type std::string str; ^
In file included from classA.cpp:3:0: classA.h:6:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 classB *ptr_b = new classB;
There is the classA.h:
#ifndef CLASSA_H
#define CLASSA_H
class classA {
private:
classB *ptr_b = new classB;
public:
classA();
};
#endif /* CLASSA_H */
classA.cpp:
#include "classB.h"
#include "classA.h"
classA::classA() {
}
classB.h:
#ifndef CLASSB_H
#define CLASSB_H
class classB {
private:
std::string str;
public:
classB();
};
#endif /* CLASSB_H */
classB.cpp:
#include <string>
#include "classB.h"
classB::classB() {
}
I apreciate all the help you can give. I don´t know how to fix this and I'm going crazy.
Thanks for reading.
#include <string>from classB.h. As it stands, <string> is included by classB.cpp but not classA.cpp (which also includes classB.h).std::string, please don't depend on indirect includes as they are fragile. If you don't use string in classB.cpp feel free to remove it.