2012-08-15 127 views
2

因此,我正在尝试使用Visual Studio 2010在C++中制作基于文本的游戏。以下是我认为相关的一些代码块。如果你需要,不要犹豫,问我。错误C2065:'无处':未声明的标识符

我想创建一个名为地方的游戏类。我做了一个地方,它有另一个“地方”,它的北部,南部,东部和西部。我现在很困惑。我是这个东西的菜鸟。我可能只是在看一些东西。

//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) 
{ 
} 
+0

更新了@dasblinkenlight的建议。 – superzilla 2012-08-15 02:49:13

+0

@dasblinkenlight我得到这4次:“1> c:\ users \杰克逊\谷歌驱动器\公共\ C++项目\ parabellum \ parabellum \ places.cpp(5):错误C2065:'无处':未声明的标识符” 由于某种原因,您的答案被删除:( – superzilla 2012-08-15 02:52:57

回答

2

以下语法将解决错误

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

即C++ 03标准解释,3.3.1/1

声明的一个名字的点立即在其完成 声明者(第8条)和其初始化者(如果有)之前

在OP示例中,place nowhere(.....)表示声明符,因此nowhere用作构造函数参数时被视为未声明。 在我的示例中,place nowhere是一个声明器,place(.....)是一个初始化器,因此nowhere在该点声明。

相关问题