Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ErrorHandling C++11 , +
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
{
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_ */
 
#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_ */
 
#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 9-Nov-12 7:13am
Edited 9-Nov-12 7:21am
v2
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 9-Nov-12 14:05pm
   
Besides, you mentioned two errors, but commented only one...
--SA
Member 9561202 at 9-Nov-12 20:58pm
   
to two error in one line
Sergey Alexandrovich Kryukov at 9-Nov-12 23:29pm
   
Sure, thank you for clarification.
--SA
Rate this: bad
good
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").
 
—SA
  Permalink  
Rate this: bad
good
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.
  Permalink  

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



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