Overloading. PLEASE HELP!!!!

Why do I get this error?
Line 12: 'Contact::Contact(std::string)' and 'Contact::Contact(std::string)' cannot be overloaded.

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
#include <string>
#include <vector>
using namespace std;

#ifndef _CONTACT_H_
#define _CONTACT_H_


class Contact {
public:
Contact(std::string FirstName);
Contact(std::string LastName);
std::string getFirstName() ;
std::string getLastName() ;
std::string getNickname() ;
std::string getEmail1() ;
std::string getEmail2() ;
std::string getPhone1() ;
std::string getPhone2() ;
std::string getAddress() ;
std::string getWebsite() ;
std::string getBirthday() ;
std::string getNotes() ;

private:
     std ::string firstname;
     std ::string lastname;
     std ::string nickname; 
     std ::string email1;
     std ::string email2; 
     std ::string phone1;
     std ::string phone2;
     std ::string address;
     std ::string website;
     std ::string birthday;
     std ::string notes;
}; 

#endif 
Last edited on
Because these two declarations

Contact(std::string FirstName);
Contact(std::string LastName);

declare the same function Contact( std::string ); The name of the parameter does not play any role in function declaration.

How can I fix this? This is what I do with each of them in my .cpp file:
1
2
3
4
Contact::Contact(std::string FirstName)
{
	firstname = FirstName;
}
Declare the construactor as

Contact::Contact( const std::string &FirstName, const std::string &LastName );

Or declare a default constructor as

Contact::Contact();
and also declare additional function as

1
2
vois setFirstName( const std::string &FirstName );
void setLastName( const std::string &LastName );
Last edited on
you can fix it by using

Contact( std::string Name) ;

instead of two constructor decleration
1
2
Contact(std::string FirstName);
Contact(std::string LastName);
Thanks so much. I have another question. Why do I get this error?
[Linked Error] undefined reference to 'AddressBook::AddressBook()'

This is my main.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
#include <iostream> 
#include <fstream>
#include "addressbook.h"

int main(){

  ifstream inStream("input.txt");
  string line, header, token;
  vector <string> tokens;
  getline (inStream, header);
  AddressBook myAddressBook;
  while(!inStream.eof())
  {
      getline (inStream, line);
      cout << line << endl;
      int x=0, y=-1;
	while(x<line.length())
        {
              x = line.find_first_of ("\"", y+1);
	      y = line.find_first_of ("\"", x+1);
	     token = line.substr(x+1,y-x-1);
             tokens.push_back (token);
             cout << token <<endl;
       	
	}	
	
}

return 0;
}


This is addressbook.cpp:
1
2
3
4
5
6
#include "addressbook.h"
AddressBook::AddressBook(){};
void AddressBook::addContact (Contact newContact)
{
      addressbook.push_back(newContact);
}


This is addressbook.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "contacts.h"

#ifndef _ADDRESSBOOK_H_
#define _ADDRESSBOOK_H_

class AddressBook 
{
public:

AddressBook();	
void addContact (Contact newContact);
        

private:
vector<Contact> addressbook;
};
#endif 
I think you do not require semicolon after the constructor definition ends

AddressBook::AddressBook(){}
Last edited on
It looks like addressbook.cpp was not included in the project. Also remove the semicolon after closing brace in the constructor definition.
thanks so much. so now how can I create a Contact with those tokens
like Contact newContact(tokens[1], tokens[2],token[3] .... tokens[11])
each token represents one of the items. ex. first name is token[1]
and where would I include this?
Last edited on
So, how could I now create a Contact with these tokens?
Topic archived. No new replies allowed.