I'm working on a problem from class. It's about creating an "addressType" class, and using it to interact with a main function that's already written out. The program doesn't work, and the main error I get is "addressType.cpp:6:7: error: redefinition of 'addressType' class addressType {". Why does it think I'm redeclaring the class? I guess I'm just not familiar enough with C++ syntax. I'm really inexperienced with C++, I was a Java guy.
Here's a sample of my .h file code...
#ifndef ADDRESSTYPE_H_INCLUDED
#define ADDRESSTYPE_H_INCLUDED
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
class addressType {
private:
string address;
string city;
string state;
int zipcode;
public:
addressType();
addressType(string inputAddress, string inputCity, string inputState, int inputZipcode);
void setAddress(string inputAddress);
void setCity (string inputCity);
//more functions i didn't paste
}; #endif
and so on. Here's a sample of the .cpp:
#include "addressType.h"
#include <iostream>
using namespace std;
class addressType {
private:
string address;
string city;
string state;
int zipcode;
public
addressType() {
address = "aa";
city = "aa";
state = "XX";
zipcode = 10000;
}
addressType(string inputAddress, string inputCity, string inputState, int inputZipcode) {
address = inputAddress;
city = inputCity;
setState(inputState);
setZipcode(inputZipcode);
}
void setAddress(string inputAddress) {
address = inputAddress;
}
//more functions I didn't paste
};
The main message I get is: addressType.cpp:6:7: error: redefinition of 'addressType' class addressType.