inner class - urgent!!

hi,
i got lots of errors while using inner class:tenant in class:building
i don't know why.. could someone help?
here are some of the errors, i coudn't copy the code- too long..
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
building.cpp

#include "Building.h"
#include <iostream>
using namespace std;
void Building::Tenant::setID(const int id)
{
if ((id>=1000000)&&(id<=999999999))
_id=id;
else
throw "incorrect id";
}
void Building::Tenant::validChars(const char* word) const
{
int lenWord = strlen(word);
for(int i=0;i<lenWord;i++)
{
if ((word[i]<'65')||(word[i]>'122'))
throw "incorrect chars";
}
}
void Building::Tenant::setName(const char* name)
{
Building::Tenant::validChars(name);
if (_name!=NULL)
delete[] _name;
_name = new char[strlen(name)+1];
if (_name!=NULL)
strcpy(_name,name);
else
throw -1;
}
void Building::Tenant::setLastName(const char* lastName)
{
Building::Tenant::validChars(lastName);
if (_lastName!=NULL)
delete[] _lastName;
_lastName = new char[strlen(lastName)+1];
if (_lastName!=NULL)
strcpy(_lastName,lastName);
else
throw -1;
}
void Building::Tenant::setPhoneNum(const int phoneNum)
{
if ((phoneNum>=0501000000)&&(phoneNum <= 0570000000))
_phoneNumber = phoneNum;
else
throw "incorrect phone number";
}
void Building::Tenant::setApartmentNum(const int apartmentNum)
{
if (apartmentNum>0)
_apartmentNumber=apartmentNum;
else
throw "incorrect apartment number";
}
void Building::Tenant::setLevel(const int level)
{
if (level>0)
_level=level;
else
throw "incorrect level";
}
void Building::Tenant::setNext(Tenant* next)
{
_next=next;
}
Building::Tenant::Tenant(const int id=0,const char* name=NULL,const char* lastName=NULL,const int phoneNum=0,const int apartmentNum=0,const int level=0,Tenant* next=NULL)
{
setID(id);
setName(name);
setLastName(lastName);
setPhoneNum(phoneNum);
setApartmentNum(apartmentNum);
setLevel(level);
_next = next;
}
Building::Tenant::Tenant(const Tenant& tenant)
{
setID(tenant.getID());
setName(tenant.getName());
setLastName(tenant.getLastName());
setPhoneNum(tenant.getPhoneNum());
setApartmentNum(tenant.getApartmentNum());
setLevel(tenant.getLevel());
_next = tenant._next;
}
void Building::Tenant::print() const
{
cout<<"Tenant ID:"<<getID()<<", name:"<<getName()<<", last name:"<<getLastName()<<", phone number:"<<getPhoneNum()<<", apartment number:"<<getApartmentNum()<<", level:"<<getLevel()<<endl;
}
char* Building::changeName=NULL;
char* Building::changeLastName=NULL;
Building::Building():_size(0)
{
char* name = new char[strlen("Moshe")+1];
strcpy(name,"Moshe");
char* lastName = new char[strlen("Mash")+1];
strcpy(lastName,"Mash");
const int id=11111111,phoneNum=0505000000,apartmentNum=1,level=1;
_head = new Building::Tenant(id,name,lastName,phoneNum,apartmentNum,level);
_size++;
}
void Building::addTenant(int id=0,char* name=NULL,char* lastName=NULL,int phoneNum=0,int apartmentNum=0,int level=0,Building::Tenant* next=NULL)
{
Building::Tenant* p_next;
for(p_next=_head;p_next==NULL;p_next++)
{
if (apartmentNum==(p_next->_apartmentNumber))
throw "incorrect, there is already such an apartment number";
}
Building::Tenant* tenant=new Building::Tenant(id,name,lastName,phoneNum,apartmentNum,level,next);
if (tenant!=NULL)
{
int i=0;
for(p_next=_head;i<=_size; p_next++,i++)
{
if ((apartmentNum < (p_next->_apartmentNumber))||(p_next==NULL))
{
Tenant* old=p_next;
p_next--;
p_next->setNext(tenant);
tenant->setNext(old);
break;
}
}
}
else
throw -1;

}
Building::Tenant* Building::getTenant(int id) const
{
Tenant* p_next;
for(p_next=_head;p_next==NULL;p_next++)
{
if (p_next->getID() == id)
return p_next;
}
throw "there is no tenant with that ID number";
}
void Building::delTenant(Tenant* next)
{
if (next!=NULL)
{
Tenant* old = next;
next--;
next->setNext(old->getNext());
delete[] old;
}
}
void Building::removeTenant(int id)
{
delTenant(getTenant(id));
_size--;
throw "the tenant was removed successfully";
}
void Building::setTenantName(int id)
{
getTenant(id)->setName(changeName);
throw " the tenant's name was changed successfully";
}
void Building::setTenantLastName(int id)
{
getTenant(id)->setLastName(changeLastName);
throw " the tenant's last name was changed successfully";
}
void Building::printAll() const
{
Tenant* p_next;
for(p_next=_head;p_next==NULL;p_next++)
{
p_next->Building::Tenant::print();
}
}
Building::~Building()
{
Tenant* p_next;
for(p_next=_head;p_next==NULL;p_next++)
{
Tenant* old = p_next;
p_next->setNext(old->getNext());
delete[] old;
}
}


most of the error are like: c2264 and c2084

47 IntelliSense: too few arguments in function call c:\users\kereni\documents\visual studio 2010\projects\oop_ex2\oop_ex2\sheltered housing seniors.cpp 24
Error 46 error C2660: 'Building::addTenant' : function does not take 6 arguments c:\users\kereni\documents\visual studio 2010\projects\oop_ex2\oop_ex2\sheltered housing seniors.cpp 22
Error 4 error C2264: 'Building::Tenant::validChars' : error in function definition or declaration; function not called c:\users\kereni\documents\visual studio 2010\projects\oop_ex2\oop_ex2\building.cpp 20

Error 39 error C2227: left of '->setName' must point to class/struct/union/generic type c:\users\kereni\documents\visual studio 2010\projects\oop_ex2\oop_ex2\building.cpp 157
Error 42 error C2227: left of '->setLastName' must point to class/struct/union/generic type c:\users\kereni\documents\visual studio 2010\projects\oop_ex2\oop_ex2\building.cpp 162
Error 2 error C2084: function 'void Building::Tenant::validChars(const char *) const' already has a body c:\users\kereni\documents\visual studio 2010\projects\oop_ex2\oop_ex2\building.cpp 10
Name(int)' already has a body c:\users\kereni\documents\visual studio 2010\projects\oop_ex2\oop_ex2\building.cpp 161
thanks!!
Take a close look at the errors:
1
2
too few arguments in function call
function does not take 6 arguments


C++ requires you to call functions exactly in the way they are defined, which the compiler is saying you aren't.

Also, when you post code, maybe add a comment on what line the errors occur, since the reported line by the compiler doesn't correspond to the line numbers of individual snippets. That way people on the forum can see where your error is and what you're doing wrong.

Don't forget to use indentation to make your code more readable.
Last edited on
remove all default arguments from your implemented functions.
It seems that you implemented function like validChars() twice (in hpp and cpp)
oh.. thank you!! finally there are no errors,indeed the problem was at the hpp file: i added by mistake after the method declaration {} instead of ..();
but now i have debugging error:
"First-chance exception at 0x7694c41f in oop_ex2.exe: Microsoft C++ exception: char at memory location 0x002ef4d4.."
and it crash at line:20
i check the exceptions- it seems fine, there are try and some catch blocks...
Topic archived. No new replies allowed.