class Base1
{
private:
int testInput;
public:
Base1();
virtual int GetRow(void) = 0;
};
Base1::Base1()
{
testInput = 0;
}
class table : public Base1
{
private:
int row;
public:
table();
virtual int GetRow(void);
};
table::table()
{
//Contructor
row = 5;
}
int table::GetRow()
{
return row;
}
int main ()
{
Base1* pBase = new table[3];
pBase[0].GetRow();
pBase[1].GetRow(); //when i get to this line, the compiler keep saying access
// violation.
pBase[2].GetRow();
return 0;
}
3 つのテーブル クラスの配列を作成しようとしています。そのためには Base オブジェクトを使用する必要があります。
Base1 * pBase = new table[3];
私には元気に見えます。しかし、各テーブルにアクセスしようとすると、コンパイラはアクセス違反だと言いました。このコードの何が問題なのかわかりません。ただし、Visual Studio 2010 を使用しています。