So, I’m trying to make a text based game in C++ Using Visual Studio 2010. Here are some of the code blocks that I think are related. If you need anymore, don’t hesitate to ask me.
I’m trying to create a class for a game called places. I make a place, and it has another “place” to the North, South, East, and West of it. I’m just really confused right now. I’m a noob at this stuff. I may just be looking over something.
//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)
{
}
Following syntax would solve the error
That is explained in C++03 standard, 3.3.1/1
In OP example,
place nowhere(.....)represents a declarator, thereforenowhereused as a constructor parameter is considered undeclared.In my example, the
place nowhereis a declarator andplace(.....)is an initializer, thereforenowherebecomes declared at that point.