This class should have a vector which has berths inside the rows.
However when I go to build this I get:
Error 1
error C2065: 'Rows' : undeclared identifier
Error 39 error C2065: 'Berths' : undeclared identifier
Error 14
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
They seem to be simple errors but I do not understand why they are occurring.
I have tried to take the approach which I was helped with last week but I am unsure what the problem was. From what I have been reading on pointers the syntax seems correct. Regarding my vectors I really do not understand how to put a vector inside a vector which seems to be the best way to approach it.
Hi there! Vectors are template based, which means you can have nearly any parameter type you can think of, including vectors of things, for example:
vector<vector<vector<vector<int> > > > quadvec;
is valid, though a bit unique, the spaces between the >'s are important to prevent the compiler from thinking you're trying to use the bitwise shift or the stream operator >>.
However I don't see anything wrong with the code you've supplied.
is valid, though a bit unique, the spaces between the >'s are important
Only pre-C++11 compilers have this problem. With the current standard the spaces are not necessary.
You probably need rethink your classes. Why do you need a Berths in Rows? Why do you need a Rows in Berths? Why do you need a instance of these classes in each of the classes?
in rows.h line 10, remove the (). That makes it look like a function declaration.
You also have recursive #includes. rows.h includes berths.h and berths.h includes rows.h. When using vector<>, the type must be fully defined. If you can't fully define the type because of recursive includes, then one of them must use pointers.
When you run into recursive includes, it often means you don't have your class hierarchy correct. i.e. Why does Berths have a vector of Rows? One would think that a ship has a vector of rows (decks?). A row has a vector of berths, but an instance of the Berths class represents a single berth, not a vector of rows.
I'm unclear why both Berths and Rows have dock/undock functions. Isn't that an attribute of a Ship?
class Ship
{
//stuff
};
class Berth
{
Ship ship;
//stuff
};
class Row
{
std::vector<Berth> berths;
//stuff
};
class Dock
{
std::vector<Row> rows;
//stuff
};
The way you had it in your opening post, assuming it actually worked, you would have a vector of Berths each containing a vector of Rows each containing a vector of Berths each containing a vector of Rows each containing a vector of Berths each containing a vector of Rows each containing a vector of Berths ad infinitum.