私は初心者です。文字列を使用できない理由がわかりません。それは言いstring does not have a type
ます。
main.cpp
#include <iostream>
#include <string>
#include "Pancake.h"
using namespace std;
int main() {
Pancake good;
good.setName("David");
cout << good.name << endl;
}
パンケーキ.h
#ifndef PANCAKE_H
#define PANCAKE_H
#include <string>
class Pancake {
public:
void setName( string x );
string name;
protected:
private:
};
#endif // PANCAKE_H
パンケーキ.cpp
#include <iostream>
#include "Pancake.h"
#include <string>
using namespace std;
void Pancake::setName( string x ) {
name = x;
}
これは、文字列を使用する場合にのみ発生します。整数を使用して、そのすべてのインスタンスを置き換えるstring x
と、機能します。しかし、なぜ?int x
string x