Person Data and Customer Classes

Hey Everyone!!
My assignment is to Design a Class named PersonData with the following members
-- last name
-- first name
-- address
-- city
-- state
--zip
--phone
Next I have to create a class named CustomerData
I created and coded everything I need but Im getting this weird error I have never seen before!

The Error is

Build/Intermediates/CustomerData.build/Debug/CustomerData.build/Objects-normal/x86_64/CustomerData.o
ld: 44 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any Help is much appreciated! Thank you in advance! Here are my files it says its from customerData.cpp file

CustomerData.cpp
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

#include "CustomerData.h"
#include <iostream>
#include <string>
using namespace std;

void CustomerData::setCustomerNumber(int cno)
{ customerNumber = cno; }

void CustomerData::setMailingList(bool ans)
{ mailingList = ans; }

int CustomerData::getCustomerNumber()
{ return customerNumber; }

bool CustomerData::getMailingList()
{ return mailingList; }

CustomerData::CustomerData()
{
    customerNumber = 0;
    mailingList = false;
}

CustomerData::CustomerData(int cno,bool ans,string lname, string fname,string a,string s, string c,string z,string ph):PersonData(lname, fname,a, s, c, z, ph)
{
    customerNumber = 0;
    mailingList = false;
};

Sorry Here are the other files! Thank you again to anyone who helps!

CustomerData.H File

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

#ifndef CustomerData_h
#define CustomerData_h

#include <iostream>
#include <string>
#include "PersonData.cpp"
using namespace std;

class CustomerData:public PersonData
{
private:
    int customerNumber;
    bool mailingList;
    
public:
    void setCustomerNumber(int cno);
    void setMailingList(bool ans);
    int getCustomerNumber();
    bool getMailingList();
    
CustomerData();
CustomerData(int cno, bool ans, string lname,
             string fname, string a, string s,
             string c, string z, string ph);
};

#endif /* CustomerData_hpp */ 



PersonData.cpp File
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
#include <iostream>
#include <string>
#include "PersonData.h"
using namespace std;

PersonData::PersonData()
{
    lastname="";
    firstname="";
    address="";
    state="";
    city="";
    zip="";
    phonenumber="";
}

PersonData::PersonData(string lname, string fname,string a,
                       string s, string c,string z,string ph)
{
    lastname=lname;
    firstname=fname;
    address=a;
    state=s;
    city=c;
    zip=z;
    phonenumber=ph;
}

void PersonData::setlastname(string lname)
{ lastname = lname; }

void PersonData::setfirstname(string fname)
{ firstname = fname; }

void PersonData::setaddress(string a)
{ address = a; }

void PersonData::setstate(string s)
{ state = s; }

void PersonData::setcity(string c)
{ city = c; }

void PersonData::setzip(string z)
{ zip = z; }

void PersonData::setphonenumber(string ph)
{ phonenumber = ph; }

string PersonData::getlastname()
{ return lastname; }

string PersonData::getfirstname()
{ return firstname; }

string PersonData::getaddress()
{ return address; }

string PersonData::getstate()
{ return state; }

string PersonData::getcity()
{ return city; }

string PersonData::getzip()
{ return zip; }

string PersonData::getphonenumber()
{ return phonenumber; }


PersonData.h file

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
#ifndef PersonData_h
#define PersonData_h

#include <iostream>
#include <string>
using namespace std;

class PersonData
{
private:
    string lastname;
    string firstname;
    string address;
    string city;
    string state;
    string zip;
    string phonenumber;

public:
    
    PersonData();
    
    PersonData(string lname, string fname,string a,
               string s, string c,string z,string ph);
    
    void setlastname(string lname);
    void setfirstname(string fname);
    void setaddress(string a);
    void setstate(string s);
    void setcity(string c);
    void setzip(string z);
    void setphonenumber(string ph);
    string getlastname();
    string getfirstname();
    string getaddress();
    string getstate();
    string getcity();
    string getzip();
    string getphonenumber();
};



#endif /* PersonData_hpp */ 


MAIN FILE
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


#include <iostream>
#include <string>
#include "CustomerData.cpp"
using namespace std;

void displayCustomer(CustomerData c);

int main()
{
    CustomerData C1;
    CustomerData C2(101,true,"Jack","Smith","CMR 345,BOX 1234", "APO","AA APO/FPO", "09250", "918-555-0123");
    cout << "Customer 1 Details:";
    displayCustomer(C1);
    cout << "Customer 2 Details:";
    displayCustomer(C2);
}

void displayCustomer(CustomerData c)
{
    cout <<"Last Name: " << c.getlastname() << endl;
    cout << "First Name: " << c.getfirstname() << endl;
    cout << "Address: " << c.getaddress() << endl;
    cout << "State: " << c.getstate() << endl;
    cout << "City: " << c.getcity() << endl;
    cout << "Zip: " << c.getzip() << endl;
    cout << "Phone Number: " << c.getphonenumber() << endl;
    
}
Why are you including the cpp files ?
Remove all the
#include "ClassName.cpp"
lines or try replacing them with the header files instead so.
Unlike the header files, the source file don't have include guards, making the same thing potentially appear twice/multiple times in a source file.
That's what the error means, the linker sees the symbols defined multiple times.
Last edited on
Topic archived. No new replies allowed.