2013-04-05 128 views
1

我想编译一个程序以确保所有代码都正常工作。我得到一个错误2019未解析的外部与以下消息:编译器错误2019无法解析的外部符号

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> > &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function "public: __thiscall Client::Client(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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> > &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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> >)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
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> > &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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> >)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
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 

这里是我的全部代码...

标题:为Client.h类 //规范文件。班级将持有会员资料并提供必要的功能以存取资料。

#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 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; 
} 

主文件:

#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() 
{ 

} 

回答

1

你还没有资格你的很多功能定义。例如:

void checkName(string &nm) 

这应该是:

void Client::checkName(string &nm) 

因为是Client类的成员。对于checkSexcheckPhone也是如此。

+0

这就是我得到的复制和粘贴。感谢您修理菜鸟。 – 2013-04-05 20:55:22

+0

@AlexMcCoy不要忘记接受,如果它的工作! – 2013-04-05 20:55:55

相关问题