Click here to Skip to main content
11,922,641 members (56,459 online)
Rate this:
Please Sign up or sign in to vote.
Hello. I write Conway Life game on C ++. I use MVC pattern. For some reason I can not create the pointer on object of the controler in the class Model and View.
#ifndef _ConwayModels_H_
#define _ConwayModels_H_

#include <list>
#include "ConwayController.h"

class ConwayModels
	void update_state(const int n);
	ConwayController *Controller; // ERROR!
	class cell
		// live or dead
		bool state;
		// coordinates
		int x, y;
	std::list<cell> live_with_neighbors;
#endif /* _ConwayModels_H_ */

#ifndef _ConwayViews_H_
#define _ConwayViews_H_

#include "IConwayViews.h"
#include "ConwayController.h"

class ConwayViews : public IConwayViews
	virtual ~ConwayViews();
	virtual void drow();
	virtual void set_cell(const int x, const int y);
	virtual void reset_cell(const int x, const int y);
	ConwayController *Controller;
#endif /* _ConwayViews_H_ */

#ifndef _ConwayController_H_
#define _ConwayController_H_

#include "Parser.h"
#include "ConwayModels.h"
#include "ConwayViews.h"
#include <string>
#include <fstream>

class ConwayController
	ConwayController() : default_input("input.txt"), default_output("output.txt") {};
	~ConwayController() {};
	// start reading and execution commands of game
	void start_game(const int argc, const char **argv);
	// read and execute next command
	void eval();
	const char *default_input;
	const char *default_output;
	// built-in parcer (aggregation)
	ArgParser Parser;
	// communication with model and view (association)
	ConwayModels *Model;
	ConwayViews *View;
	// io files
	ifstream in;
	ofstream out;
#endif /* _ConwayController_H_ */
I write a code in microsoft visual studio 2012.
Prompt please because of what it occurs?
Posted 9-Nov-12 8:13am
Edited 9-Nov-12 8:21am
Why would you keep silence on the exact error messages? Of course, anyone could look up the reference manual, but why?
Member 9561202 9-Nov-12 20:59pm
1)\gamelife\conwaymodels.h(13): error C2143: syntax error : missing ';' before '*'
2)\gamelife\gamelife\conwaymodels.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Besides, you mentioned two errors, but commented only one...
Member 9561202 9-Nov-12 20:58pm
to two error in one line
Sure, thank you for clarification.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

From the first glance: in the class ConwayModels, ConwayController field is private, declared but never used. It is never initialized (with "new").

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Cyclical dependence on a Contoller. Model and View do not know about real Conroller, only Interface Controller. The model and view shan't be crossed. Thanks to all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151125.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100