错误C2143和错误C4430 C ++ MS VS 2012 [英] error C2143 and error C4430 C++ MS VS 2012
本文介绍了错误C2143和错误C4430 C ++ MS VS 2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好.我用C ++编写Conway Life游戏.我使用MVC模式.由于某种原因,我无法在模型和视图类中在控件的对象上创建指针.
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_ */
我在Microsoft Visual Studio 2012中编写代码.
I write a code in microsoft visual studio 2012.
Prompt please because of what it occurs?
推荐答案
乍一看:在类ConwayModels
中,ConwayController
字段是私有的,已声明但从未使用过.永远不会初始化(使用"new
").
—SA
From the first glance: in the classConwayModels
,ConwayController
field is private, declared but never used. It is never initialized (with "new
").
—SA
对Contoller的循环依赖性. Model和View不了解真正的Conroller,仅了解Interface Controller.模型和视图可能会交叉.谢谢大家.
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.
这篇关于错误C2143和错误C4430 C ++ MS VS 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文