I'm new to using vectors and some may see this as a trivial problem. If you have any suggestion on how I can improve the program, I welcome your input.

code(with problem):

#ifndef CMONOPOLY_HPP
#define CMONOPOLY_HPP

#include <vector>
#include "head.hpp"

namespace CMonopoly
{
	class CMonopoly
	{
	public:
		~CMonopoly();
		void PrintWelcome();
		void SetUpPlayers();
		void FillBoard();
	private:
		void CreateSpecial(char a[]);
		void CreateSquare(char a[], const int SIZE);
		vector<CBoard *> Board;
		vector<CPlayers *> Players;
	};
}
#endif

Error message:

1>------ Build started: Project: MonopolyGame, Configuration: Debug Win32 ------
1>Build started 23/02/2012 08:25:04.
1>InitializeBuildStatus:
1> Touching "Debug\MonopolyGame.unsuccessfulbuild".
1>ClCompile:
1> main.cpp
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(6): error C2882: 'CMonopoly' : illegal use of namespace identifier in expression
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(6): error C2065: 'monopoly' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(6): error C2061: syntax error : identifier 'CMonopoly'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(8): error C2065: 'monopoly' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(8): error C2227: left of '->PrintWelcome' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(9): error C2065: 'monopoly' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(9): error C2227: left of '->SetUpPlayers' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(10): error C2065: 'monopoly' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\main.cpp(10): error C2227: left of '->FillBoard' must point to class/struct/union/generic type
1> type is ''unknown-type''
1> CSquare.cpp
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2238: unexpected token(s) preceding ';'
1> CSpecial.cpp
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2238: unexpected token(s) preceding ';'
1> CPlayers.cpp
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2238: unexpected token(s) preceding ';'
1> CMonopoly.cpp
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(16): error C2065: 'Board' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(16): error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(16): error C2065: 'Board' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(16): error C2228: left of '.start' must have class/struct/union
1> type is ''unknown-type''
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(18): error C2065: 'Board' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(21): error C2065: 'Board' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(21): error C2541: 'delete' : cannot delete objects that are not pointers
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(23): error C2065: 'Player' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(23): error C2228: left of '.end' must have class/struct/union
1> type is ''unknown-type''
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(23): error C2065: 'Player' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(23): error C2228: left of '.start' must have class/struct/union
1> type is ''unknown-type''
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(25): error C2065: 'Player' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(28): error C2065: 'Player' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(28): error C2541: 'delete' : cannot delete objects that are not pointers
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(71): error C2065: 'Board' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(71): error C2228: left of '.push_back' must have class/struct/union
1> type is ''unknown-type''
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(101): error C2065: 'Board' : undeclared identifier
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.cpp(101): error C2228: left of '.push_back' must have class/struct/union
1> type is ''unknown-type''
1> CBoard.cpp
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cspecial.hpp(7): error C2504: 'CBoard' : base class undefined
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\csquare.hpp(7): error C2504: 'CBoard' : base class undefined
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(19): error C2238: unexpected token(s) preceding ';'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2143: syntax error : missing ';' before '<'
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>\\lha-003\pers-h\0005c42b\downloads\kzaman (1)\kzaman\monopolygame\cmonopoly.hpp(20): error C2238: unexpected token(s) preceding ';'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:07.12
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Recommended Answers

All 3 Replies

using namespace std;
...right before your class...
...best on line 6

Actually, I would much prefer that you wrote line 19/20 as:

std::vector<CBoard *> Board;
std::vector<CPlayers *> Players;

because what is the point of having namespaces and then just importing everything.

Also putting using namespace std; in at header file!!! Somewhere later, you are just going to import that into your code and make a complete mess because you will have then polluted the global namespace will all of std without knowing it. Errors like that take for ever to debug.

Secondly, you are using pointers in a vector, that is not a problem (assuming you are careful), but you do not have a constructor, copy constructor or an assignment operator. All three are auto generated by the compiler, and the last two are 99.9% likely to be very very wrong and will cause your code to crash in very unexpected ways.

commented: Solid advice +12

Actually, I would much prefer that you wrote line 19/20 as:

std::vector<CBoard *> Board;
std::vector<CPlayers *> Players;

because what is the point of having namespaces and then just importing everything.

Also putting using namespace std; in at header file!!! Somewhere later, you are just going to import that into your code and make a complete mess because you will have then polluted the global namespace will all of std without knowing it. Errors like that take for ever to debug.

Secondly, you are using pointers in a vector, that is not a problem (assuming you are careful), but you do not have a constructor, copy constructor or an assignment operator. All three are auto generated by the compiler, and the last two are 99.9% likely to be very very wrong and will cause your code to crash in very unexpected ways.

I've included your recommended code and the program no long brings up an error in that file.

The program is in the process of being built and not got round to including the copy constructor or overloading the assignment operator.

Thanks for you input.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.