1

I am trying to compile a program to make sure all the code is working. I am getting an Error 2019 Unresolved External with the following messages:

1>------ Build started: Project: Week 2 Dating Service, Configuration: Debug Win32 ------
1>  Client.cpp
1>Client.obj : error LNK2019: unresolved external symbol "private: void __thiscall Client::checkName(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?checkName@Client@@AAEXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall Client::Client(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Client@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>Client.obj : error LNK2019: unresolved external symbol "private: void __thiscall Client::checkSex(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?checkSex@Client@@AAEXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall Client::Client(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Client@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z)
1>Client.obj : error LNK2019: unresolved external symbol "private: void __thiscall Client::checkPhone(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?checkPhone@Client@@AAEXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall Client::Client(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Client@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
1>C:\Users\owner\Documents\Visual Studio 2010\Projects\CISS 350\Week 2 Dating Service\Debug\Week 2 Dating Service.exe : fatal error LNK1120: 3 unresolved externals

Here is all of my code...

Header: //Specification file for the Client.h class. Class will hold member data and provide necessary functions to access the data.

#ifndef CLIENT_H
#define CLIENT_H
#include <iostream>
#include <vector>

using namespace std;

class Client
{
private:
//Member Variables
string name;    //Hold the clients name
string sex; //Single char to hold sex
string phone; //Holds 7 digit phone number
vector<string> interests;

//Private Member functions
void interest(vector<string>);
void checkName(string &);
void checkSex(string &);
void checkPhone(string &);

public:
//Public Variables
bool hasMatch;
string match;

//Constructors
Client();
Client(string);
Client(string, string);
Client(string, string, string);
Client(string, string, string, vector<string>);

//Mutators
void setName(string);
void setSex(string);
void setPhone(string);
void setInterests(vector<string>);
void setClient(string, string, string, vector<string>);


//Accessors
void getName(string &);
void getSex(string &);
void getPhone(string &);
void getInterests(vector<string> &);
void getClient(string &, string &, string &, vector<string> &);

};


#endif

Implementation file:

//Implementation file for the Client.h class. 

#include <iostream>
#include <string>
#include <vector>
#include "Client.h"

using namespace std;

//Private Member functions
void Client::interest(vector<string> inter)
{
int vecSize = inter.size();
for(int i = 0; i < vecSize; i++)
{
    interests[i] = inter[i];
}
}
void checkName(string &nm)
{
do
{
    cout << "Name is longer than 20 characters. Please enter a new name:";
    cin >> nm;
} 
while(nm.size() > 20);
}
void checkSex(string &sx)
{
int size = sx.size();

if(size > 1)
{
    sx = sx[0];
}

do
{
    if(sx != "M" || sx != "m" || sx != "F" || sx != "f")
    {
        cout << "Please enter sex(M or F):";
        cin >> sx;
    }
}
while(sx != "M" || sx != "m" || sx != "F" || sx != "f");
}
void checkPhone(string &ph)
{
int size = ph.size();
bool isGood= true;

if(size > 8)
    isGood = false;

for(int i = 0; i < size; i++)
{
    if(static_cast<int>(ph[i]) != 32 && ph[i] > '9'|| ph[i] < '0')
    {
        isGood = false;
    }
}

if(isGood == false)
{
    cout << "Phone number not valid.\n" << "Please enter a new number:";
    cin >>ph;
    checkPhone(ph);
}
}

//Contructors
Client::Client()
{
name = " ";
phone = " ";
sex = " ";
interests[0] = " ";
hasMatch = false;
match = " ";
}

Client::Client(string nm)
{
checkName(nm);
name = nm;
phone = " ";
sex = " ";
interests[0] = " ";
hasMatch = false;
match = " ";
}

Client::Client(string nm, string sx)
{
checkName(nm);
name = nm;
phone = " ";
checkSex(sx);
sex = sx;
interests[0] = " ";
hasMatch = false;
match = " ";
}

Client::Client(string nm, string sx, string ph)
{
checkName(nm);
name = nm;
checkPhone(ph);
phone = ph;
checkSex(sx);
sex = sx;
interests[0] = " ";
hasMatch = false;
match = " ";
}

Client::Client(string nm, string sx, string ph, vector<string> inter)
{
checkName(nm);
name = nm;
checkPhone(ph);
phone = ph;
checkSex(sx);
sex = sx;
interest(inter);
hasMatch = false;
match = " ";
}

//Mutators
void Client::setName(string nm)
{
checkName(nm);
name = nm;
}
void Client::setSex(string sx)
{
checkSex(sx);
sex = sx;
}
void Client::setPhone(string ph)
{
checkPhone(ph);
phone = ph;
}
void Client::setInterests(vector<string> inter)
{
interest(inter);
}
void Client::setClient(string nm, string sx, string ph, vector<string> inter)
{
checkName(nm);
name = nm;
checkPhone(ph);
phone = ph;
checkSex(sx);
sex = sx;
interest(inter);
}

//Accessors
void Client::getName(string &nm)
{
nm = name;
}
void Client::getSex(string &sx)
{
sx = sex;
}
void Client::getPhone(string &ph)
{
ph = phone;
}
void Client::getInterests(vector<string> &inter)
{
inter = interests;
}
void Client::getClient(string &nm, string &sx, string &ph, vector<string> &inter)
{
nm = name;
sx = sex;
ph = phone;
inter = interests;
}

Main file:

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <list>
#include "Client.h"

using namespace std;

//Global Variables


//Function Prototypes
char MainMenu();
void AddMenu();
void PrintMenu();
bool InitLoad();
void closeProgram();


int main()
{
list<Client> males;
list<Client> females;
Client mClient;
Client fClient;

char choice;

do
{
choice = MainMenu();


switch(choice)      //Switch to to call either user selection
    {
    case ('1'):
        {
            AddMenu();
            break;
        }
    case ('2'):
        {
            PrintMenu();
            break;
        }
    case ('3'):
        {
            closeProgram(); 
        }
    }
}
while(choice <= '3' || choice >= '1' || isalpha(choice));       //input      validation to ensure the user selects an acceptable value
}

char MainMenu()
{
char choice;    //For main menu choice
cout << endl;
do
{
cout << "Main Menu\n" << "1. Client Menu\n" << "2. Print Menu\n" 
        << "3. Exit\n";
    cout << "Selection: ";
    cin >> choice;
    cout << endl;
}   
while(choice < '1' || choice > '3' || isalpha(choice));     //input validation to ensure the user selects an acceptable value

return choice;
}
void AddMenu()
{
char choice;    //For main menu choice
cout << endl;
do
{
cout << "Client Menu\n" << "1. Add Client\n" << "2. UnMatch Client\n" 
        << "3. Match Client\n" << "4. Return\n";
    cout << "Selection: ";
    cin >> choice;
    cout << endl;
}   
while(choice < '1' || choice > '4' || isalpha(choice));     //input validation to ensure the user selects an acceptable value
 }
void PrintMenu()
{
char choice;    //For main menu choice
cout << endl;
do
{
cout << "Print Menu\n" << "1. Print Matched Clients\n" << "2. Print Free Clients\n" 
        << "3. Print All Clients\n" << "4. Return\n";
    cout << "Selection: ";
    cin >> choice;
    cout << endl;
}   
while(choice < '1' || choice > '4' || isalpha(choice));     //input validation to ensure the user selects an acceptable value
}
bool InitLoad()
{
return true;
}
void closeProgram()
{

}
4

1 回答 1

1

You haven't qualified many of your function definitions. For example:

void checkName(string &nm)

This should be:

void Client::checkName(string &nm)

Because it is a member of the Client class. The same is true for checkSex and checkPhone.

于 2013-04-05T20:29:07.493 回答