2

そこで、VisualStudio2010を使用してC++でテキストベースのゲームを作成しようとしています。これが関連していると思われるコードブロックの一部です。もう必要な場合は、遠慮なく私に聞いてください。

場所というゲームのクラスを作成しようとしています。私は場所を作ります、そしてそれはそれの北、南、東、そして西に別の「場所」を持っています。私は今本当に混乱しています。私はこのようなものの初心者です。私はただ何かを見ているだけかもしれません。

//places.h------------------------
#include "place.h"

//Nowhere place
string nowheredescr = "A strange hole to nowhere";
place nowhere(&nowheredescr, &nowhere, &nowhere, &nowhere, &nowhere); //Error occurs here
//

//place.h------------------------
#ifndef place_h
#define place_h

#include "classes.h"

class place
{
public:
    place(string *Sdescription, place *Snorth, place *Ssouth, place *Swest, place *Seast);
    ~place(void);
private:
    string *description;
    place *north;
    place *south;
    place *east;
    place *west;
};

#endif

//place.cpp-------------------
#include "place.h"
#include <iostream>


place::place(string *Sdescription, place *Snorth, place *Ssouth, place *Swest, place *Seast)
{
    description = Sdescription;
    north = Snorth;
    south = Ssouth;
    west = Swest;
    east = Seast;
}


place::~place(void)
{
}
4

1 に答える 1

2

次の構文はエラーを解決します

place nowhere = place(&nowheredescr, &nowhere, &nowhere, &nowhere, &nowhere);

これは、C ++ 03標準、3.3.1/1で説明されています。

名前の宣言のポイントは、完全な宣言子(8節)の直後で、初期化子(存在する場合)の前です。

OPの例でplace nowhere(.....)は、は宣言子を表します。したがってnowhere、コンストラクターパラメーターとして使用される場合は宣言されていないと見なされます。私の例では、place nowhereは宣言子でplace(.....)あり、初期化子であるため、nowhereその時点で宣言されます。

于 2012-08-15T06:27:27.407 に答える