get an Error Message and there's no reason

Hi, I wrote some simple code, I made a very similar program, and that one run smoothly, this one show me some errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "MailMsg.h"
#include "MailBox.h"

class Factory{
public:
	virtual ~Factory();
	virtual MailMsg* createMsg() const = 0;
	virtual MailBox* createBox() const = 0;
};

class SmartFactory : public Factory{
public:
	SmartFactory();
	~SmartFactory();
	MailMsg* createMsg() const{
		return new SmartMsg();
	}
	MailBox* createBox() const{
		return new SmartBox();
	}
};

class TabFactory : public Factory{
public:
	TabFactory();
	~TabFactory();
	MailMsg* createMsg() const{
		return new TabMsg();
	}
	MailBox* createBox() const{
		return new TabBox();
	}
};

#include "MailMsg.h"
#include "MailBox.h"
#include "Factory.h"


int start(bool isTablet){
	Factory* fa = 0;

	if(isTablet){
		fa = new TabFactory;
	}
	else{
		fa = new SmartFactory;
	}

	MailMsg* mm = 0;
	MailBox* mb = 0;
	//FIXME
	mb->addMsg(mm);
	mb->draw();
	mm->draw();

	return 0;
}

#include <string>

class MailMsg{
public:
	MailMsg();
	MailMsg(std::string sender, std::string subject);
	virtual ~MailMsg();
	virtual void draw() = 0;

	const std::string& getSender() const {
		return sender;
	}

	const std::string& getSubject() const {
		return subject;
	}

private:
	std::string sender;
	std::string subject;
};

MailMsg::MailMsg(std::string sender, std::string subject){
	this->sender = sender;
	this->subject = subject;
}

class MailBox{
public:
	MailBox();
	MailBox(std::string name);
	virtual ~MailBox();
	virtual void draw() = 0;
	virtual void addMsg(MailMsg* msg);

	const std::string& getMailBoxName() const {
		return mailBoxName;
	}

	const std::vector<MailMsg*>& getMessages() const {
		return messages;
	}

private:
	std::string mailBoxName;
	std::vector<MailMsg*> messages;
};

MailBox::MailBox(std::string name){
	mailBoxName = name;
}


the error is: "unknown type name SmartFactory" and "unknown type name TabFactory"
What I'm doing wrong?
Thank you in advance
Last edited on
You did not provide mailmsg.h or mailbox.h so I don't know what those classes look like nor can I compile your program.

Line 16: You try to return an object of type SmartMsg, but no declaration of SmartMsg has been seen. As pointed out this may be in mailmsg.h, but you did not provide that.

Line 19: Ditto for SmartBox.

Line 28: Ditto for TabMsg.

Line 31: Ditto for TabBox.

Line 53: Guaranteed to crash. Reference to null pointer.



Last edited on
Topic archived. No new replies allowed.