Constructor Question! D:
Oct 18, 2015 at 10:26pm UTC
Not sure what the issue here is but I can't get the code below to compile. I think it's an issue in my Constructor but can't seem to figure out what's going on here. The error I am getting is:
Person::Person(std::string) member function already defined or decalred
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
#include <iostream>
using namespace std;
#include <string>
class Person
{
public :
//---------CONSTRUCTORS----------------
Person(string x)
{
setName(x);
}
Person(string z)
{
setLocation(z);
}
Person(int y)
{
setAge(y);
}
// ---------------- SETTERS ----------------
void setName(string x) // x is name, setter doesn't return anything so void
{
name = x;
}
void setLocation(string z) // z is location
{
location = z;
}
void setAge(int y) // y is age
{
age = y;
}
//----------------GETTERS--------------
string getLocation()
{
return location;
}
int getAge()
{
return age;
}
string getName()
{
return name;
}
private :
string name;
int age;
string location;
};
Oct 18, 2015 at 10:36pm UTC
Solved:
Person(string z) removed
Modified Person(string x) to:
1 2 3 4 5
Person(string x)
{
setName(x);
setLocation(x);
}
Last edited on Oct 18, 2015 at 10:37pm UTC
Topic archived. No new replies allowed.