C++ Unknown Type Name 'String'
I'm Working on a C++ Header File and I Keep Getting the Error "Unknown Type Name 'String'; Did You Mean 'Std: :String'?" #Include Is Already at the Top of My...
I'm working on a C++ header file and I keep getting the error "Unknown type name 'string'; did you mean 'std::string'?" #include <string> is already at the top of my code, so I'm not sure how else to remedy this issue. Any thoughts? I'm using Xcode, if that makes any difference.
#ifndef POINT_HPP
#define POINT_HPP
#include <string>
using namespace std;
class Point {
public:
Point();
Point(int pInitX, int pInitY);
Point(int pInitX, int pInitY, int pInitColor);
double distance(Point pAnotherPoint);
int getColor();
int getX();
int getY();
void move(int pNewX, int pNewY);
void setColor(int pNewColor);
void setX(int pNewX);
void setY(int pNewY);
string toString; // Error: Unknown type name 'string'; did you mean 'std::string'?
private:
void init(int pInitX, int pInitY, int pInitColor);
int mColor;
int mX;
int mY;
};
#endif
2 Answers
you must use std::string toString()or declare using namespace std;globally
Make sure to also set the path to the Point class (header and cpp) inside CMakeLists.txt.
If you are using QT, it should be something like
set(PROJECT_SOURCES
...
point.cpp
point.h
)
After that you need to import the string class at the top like this #include <string> and then declare using namespace std;