私はVisual C++ 2008 Express EditionでC++プログラミングを学んでいます。私のプログラムはstd::string
データ型を識別していません。私は<string>
ライブラリを含んでいます。私はクラスの長方形で文字列型のプライベート変数を宣言するときC++の文字列データ型が認識されない
#include "stdafx.h"
#include <iostream>
#include "TestClass.h"
#include <string>
using namespace std;
class Rectangle {
private:
int width;
int height;
double area;
string name;
public:
Rectangle()
{
width = 0;
height = 0;
}
int getWidth()
{
return width;
}
int getHeight()
{
return height;
}
void setWidth(int width)
{
this->width = width;
}
void setHeight(int height)
{
this->height= height;
}
void setArea()
{
area = width * height;
}
double getArea()
{
return area;
}
Rectangle (const Rectangle & x)
{
this->area = x.area;
}
void friendtestfunction(Rectangle2 s)
{
cout << "" << s.name;
}
};
int Rectangle2::stat_var = 5;
int _tmain(int argc, _TCHAR* argv[])
{
Rectangle rect;
rect.setWidth(10);
rect.setHeight(20);
rect.setArea();
cout<< "height is equal to :" << rect.getHeight() << endl;
cout<< "width is equal to :" << rect.getWidth() << endl;
cout << "area is equal to :" << rect.getArea() << endl;
getchar();
return 0;
}
それは次のエラーを示した:
1>c:\users\subith.p\documents\visual studio 2008\projects\test\test\testclass.h(10) : error C2146: syntax error : missing ';' before identifier 'name'
1>c:\users\subith.p\documents\visual studio 2008\projects\test\test\testclass.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
はstdafx.hを失います。以前の実行がキャッシュされ、変更してもクリアされない場合は、後で再コンパイルするときに変更が表示されません。 – xaxxon
コンパイラは、ソースファイルの先頭から開始し、コンパイラがソースファイルの一番下で停止して停止するまで下がります。だからまだ何か(#includeのような)を見たことがないなら、それを使用しようとするとそれについてはわかりません。ファイル全体を "見て"何が起きているのか把握していないし、コードをコンパイルしてコンパイルします。これはコードを1回だけ処理するため、「シングルパスコンパイラ」と呼ばれています。 –
xaxxon