私は地域と呼ばれるクラスを持っていて、私はエリアと呼ぶ別のクラスを持っています。メインクラスのAreaでは、Regionクラスオブジェクトの配列が必要です。ここで 内部に別のクラスのクラスオブジェクトの配列を持つクラスを持つことはできますか?
は私の領域クラスである:私の地域のクラスで今すぐclass Region
{
public:
// Constructor
Region();
// Get/set functions
bool getPoly() {return poly;}
bool setPoly(bool value) {poly = value;}
long getMesh() {return mesh;}
void setMesh(long value) {mesh = value;}
long getVisibleNum() {return visibleNum;}
void setVisibleNum(long value) {visibleNum = value;}
// Visibility vector
void reserveSpace();
long addVisibleRegion(int region);
long getSize(){return visibility.size();}
friend class Area;
private:
bool poly; // Does the region have polygons?
long mesh; // The reference to a 0x36 mesh
long visibleNum; // The number of visible regions
};
、私はこの ような何かを宣言しようとしています:
class Area
{
public: // Some public class functions
private:
Region* regionArray; // this should be pointers to an array of class objects
}
Areaクラスのコンストラクタでは、私が割り当てられます私が望むクラスオブジェクトの数。
私はこのエラーを取得しています:
error C2143: syntax error : missing ';' before '*'
error C4430: missing type specifier - int assumed.
Note: C++ does not support default-int
だから私は、私はそれを正しく設定しておりませんと仮定します。 Regionが構造体だったときは完全に機能しましたが、クラスであるため、私は何か間違っていると思います。
どのようにファイルをインクルードするのですか?異なるファイルにありますか、他のクラスのプロトタイプを他のヘッダに追加しましたか? –
'Area'の定義には、閉じ括弧の後にセミコロンがありません。 – fredoverflow
また、 'Region *'の代わりに 'std :: vector'を使うことを強くお勧めします。これは 'Area'オブジェクトの正確なコピー動作を確実に確実にします。 [関連するFAQ](http://stackoverflow.com/questions/4172722/) –
fredoverflow