Need help, please guide me on this.
How to solve the errors as stated below?
30:24:error:expected ‘)’ before ‘,’ token
In member function ‘int Address::compareTo(const Address&)’:
41:26:error:’std::string’ has no member named ‘compareTo’
#include<iostream>
using namespace std;
class Address {
int houseNumber;
string street;
int apartmentNumber;
string city;
string state;
string zipCode; // e.g., "47405-1234"
Address(int houseNumber,
string street,
// no apartmentNumber
string city,
string state,
string zipCode) {
this->houseNumber = houseNumber;
this->street = street;
this->city = city;
this->state = state;
this->zipCode = zipCode;
}
Address(int houseNumber,
string street,
int apartmentNumber,
string city,
string state,
string zipCode) {
this(houseNumber, street, city, state, zipCode);
this->apartmentNumber = apartmentNumber;
}
void print(void) {
std::cout << "Street: " << street << "\nCity: "
<< city << "\nState: " << state << "\nPostal Code: " << zipCode;
}
int compareTo(const Address &a) {
// same conventions as for Strings
return this->zipCode.compareTo(a);
}
};
The function you’re looking for is
compare, notcompareTo(Java, C# anyone)?Also, note that
angleis not declared in your scope. Did you mean:or did you just omit the variable?
You also (“should” where applicable):
this->compareyou can use==(this returnstruefor equality)printandcompareToshould be marked asconstusing namespace std;from the headerstringparameters to the constructor byconst &…