私自身の理解のために、ベクター クラスを再作成しようとしています。このコードをコンパイルしようとしているときに、Visual Studio 2013 で最近問題が発生しました。次のような「vector」キーワードごとにエラーが発生します。
これがクラス定義内の範囲エラーなのか、それとも別のエラーなのかわかりません。設定で遊んだことはありません。
#include "../../../std_lib_facilities.h"
class vector{
int sz;
double* elem; //pointer to the first element (of type double)
public:
vector(int s) :sz(s), //constructor - allocates s doubles , :size(s) is a 'initilization list'
elem(new double[s])
{
for (int i = 0; i < s; i++)
elem[i] = 0; //initialize elements
}
int size() const
{
return sz;
}
//read
double get(int n)
{
return elem[n];
}
//write
void set(int n, double v)
{
elem[n] = v;
}
//Every class that owns a resource needs a destructor
~vector() //destructor
{
delete[] elem; // free memory
}
};
int main(int argc)
{
vector v(5);
for (int i = 0; i < v.size(); i++){
v.set(i, i);
cout << "v[" << i << "]==" << v.get(i) << '\n';
}
system("PAUSE");
}
さらに情報が必要な場合は、お気軽にお問い合わせください。