Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
2.00/5 (1 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.
C++
#ifndef _ConwayModels_H_
#define _ConwayModels_H_

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

class ConwayModels
{
public:
	ConwayModels();
	void update_state(const int n);
private:
	ConwayController *Controller; // ERROR!
	class cell
	{
		// live or dead
		bool state;

		// coordinates
		int x, y;
	};

	std::list<cell> live_with_neighbors;
};

#endif /* _ConwayModels_H_ */


C++
#ifndef _ConwayViews_H_
#define _ConwayViews_H_

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

class ConwayViews : public IConwayViews
{
public:
	ConwayViews();
	
	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);
private:
	ConwayController *Controller;
};

#endif /* _ConwayViews_H_ */


C++
#ifndef _ConwayController_H_
#define _ConwayController_H_

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

class ConwayController
{
public:
	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();
private:
	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
Updated 9-Nov-12 7:21am
v2
Comments
Sergey Alexandrovich Kryukov 9-Nov-12 14:04pm    
Why would you keep silence on the exact error messages? Of course, anyone could look up the reference manual, but why?
--SA
Member 9561202 9-Nov-12 20:59pm    
Sorry.
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
Sergey Alexandrovich Kryukov 9-Nov-12 14:05pm    
Besides, you mentioned two errors, but commented only one...
--SA
Member 9561202 9-Nov-12 20:58pm    
to two error in one line
Sergey Alexandrovich Kryukov 9-Nov-12 23:29pm    
Sure, thank you for clarification.
--SA

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

—SA
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900