C++ C++;使用MinGW的链接器编程错误

C++ C++;使用MinGW的链接器编程错误,c++,C++,我的代码中有一个链接器错误,我无法检测到它。 我认为错误在addressBookType类中,但我无法检测到它 main有什么问题吗 或者问题在类定义中 ~z~请帮帮我 Compiler: MinGW GCC 4.6.2 32-bit Executing g++.exe... g++.exe "D:\New Folder\Cpp\Assignment 4\q4\main.cpp" -o "D:\New Folder\Cpp\Assignment 4\q4\main.exe" -I"E:\

我的代码中有一个链接器错误,我无法检测到它。 我认为错误在
addressBookType
类中,但我无法检测到它

main
有什么问题吗

或者问题在类定义中

~z~请帮帮我

Compiler: MinGW GCC 4.6.2 32-bit
Executing  g++.exe...
g++.exe "D:\New Folder\Cpp\Assignment 4\q4\main.cpp" -o "D:\New Folder\Cpp\Assignment 4\q4\main.exe"    -I"E:\Program Files\Dev-Cpp\MinGW32\include"  -I"E:\Program Files\Dev-Cpp\MinGW32\include"   -L"E:\Program Files\Dev-Cpp\MinGW32\lib" -L"E:\Program Files\Dev-Cpp\MinGW32\lib" -static-libstdc++ -static-libgcc 
E:\DOCUME~1\@$L@()V)\LOCALS~1\Temp\ccHC7fsV.o:main.cpp:(.text+0x7a8): undefined reference to `addressBookType::addressBookType()'
E:\DOCUME~1\@$L@()V)\LOCALS~1\Temp\ccHC7fsV.o:main.cpp:(.text+0x7d6): undefined reference to `addressBookType::addressBookType()'
collect2: ld returned 1 exit status
代码是:

#include<iostream>
#include<cstdlib>
#include<fstream>
#include<string>

using namespace std;

//////////////////////////////"personType" is from D.S Malik Course Website
////////////***Class person Start


class personType
{
public:
     void print() const;
       //Function to output the first name and last name
       //in the form firstName lastName.


    void setName(string first, string last);
      //Function to set firstName and lastName according 
      //to the parameters.
      //Postcondition: firstName = first; lastName = last

    string getFirstName() const;
      //Function to return the first name.
      //Postcondition: The value of firstName is returned.

    string getLastName() const;
      //Function to return the last name.
      //Postcondition: The value of lastName is returned.

    personType(string first, string last);
      //Constructor
      //Sets firstName and lastName according to the parameters.
      //The default values of the parameters are null strings.
      //Postcondition: firstName = first; lastName = last  

 private:
    string firstName; //variable to store the first name
    string lastName;  //variable to store the last name
};
/////////Class person End***///////////
// IMPLEMENTATION OF "PersonType" CLASS  //

///////////////// IMP START ////////////////////
personType::personType(string first="",string last=""){

}

void personType::setName(string first,string last){
    firstName=first;
    lastName=last;

}

string personType::getFirstName() const{

return firstName;
}

string personType::getLastName () const{
return lastName;
}

void personType::print() const{
    cout<<firstName<<" "<<lastName<<endl;
}
////////////////// IMP END ////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////


////////***class addressType Start

class addressType{


    private:
    string stAddress;
    string city;
    string state;
    string zipcode;

    public:
        addressType();
        addressType(string,string,string,string);
        void setAddress(string);
        string getAddress();
        void setCity(string);
        string getCity();
        void setState(string);
        string getState();
        void setZipcode(string);
        string getZipcode();

};

// IMPLEMENTATION OF "addressType" CLASS  //

///////////////// IMP START ////////////////////
addressType::addressType(string=" ",string=" ",string=" ",string=" "){

}

void addressType::setAddress(string addr){
    stAddress=addr;
}

string addressType::getAddress(){
    return stAddress;
}

void addressType::setCity(string cit){
    city=cit;
}

string addressType::getCity(){
    return city;
}

void addressType::setState(string sta){
    state=sta;
}

string addressType::getState(){
    return state;
}

void addressType::setZipcode(string zip){
    zipcode=zip;
}

string addressType::getZipcode(){
    return zipcode;
}
///////////////// IMP END ////////////////////

//////////class addressType End***
/////////////////////////////////


//////////////////////////////////
//////***class extPersonType Start
class extPersonType {

    private:
        string relation;
        string phNo;

    public:
        extPersonType();
        extPersonType(string,string);
        void setRelation(string);
        string getRelation();
        void setphNo(string);
        string getphNo();


};


// IMPLEMENTATION OF "extPersonType" CLASS   //
///////////////// IMP START ////////////////////

extPersonType::extPersonType(string =" " ,string = " "){

}

void extPersonType::setRelation(string rel){
    relation=rel;
}

string extPersonType::getRelation(){
    return relation;
}

void extPersonType::setphNo(string ph){
    phNo=ph;
}

string extPersonType::getphNo(){
    return phNo;
}

///////////////// IMP END ////////////////////
//////////class extPersonType End***

///////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////"dateType" is from D.S Malik Course Website
////////***class DateType Start

class dateType
{
public:
    void setDate(int month, int day, int year);
      //Function to set the date.
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters.
      //Postcondition: dMonth = month; dDay = day;
      //               dYear = year

    int getDay() const;
      //Function to return the day.
      //Postcondition: The value of dDay is returned.

    int getMonth() const;
      //Function to return the month.  
      //Postcondition: The value of dMonth is returned.

    int getYear() const;
      //Function to return the year.     
      //Postcondition: The value of dYear is returned.

    void printDate() const;
      //Function to output the date in the form mm-dd-yyyy.

    dateType(int month = 1, int day = 1, int year = 1900);
      //Constructor to set the date
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters.
      //Postcondition: dMonth = month; dDay = day; dYear = year;
      //               If no values are specified, the default 
      //               values are used to initialize the member
      //               variables.

private:
    int dMonth; //variable to store the month
    int dDay;   //variable to store the day
    int dYear;  //variable to store the year
};
//////////class dateType End***
/////////////////////////////////


// IMPLEMENTATION OF "DateType" CLASS   //
///////////////// IMP START ////////////////////

void dateType::setDate(int month, int day, int year)
{
    dMonth = month;
    dDay = day;
    dYear = year;
}

int dateType::getDay() const 
{
    return dDay;
}

int dateType::getMonth() const 
{
    return dMonth;
}

int dateType::getYear() const 
{
    return dYear;
}

void dateType::printDate() const
{
    cout << dMonth << "-" << dDay << "-" << dYear;
}

    //Constructor with parameters
dateType::dateType(int month, int day, int year) 
{ 
    dMonth = month;
    dDay = day;
    dYear = year;
}
//////////////// IMP END /////////////////////

////////////////////////////////////////////////////////////////////////////////


//////***class addressBookType Start

class addressBookType {

private:
    string FirstName; //variable to store the first name
    string LastName;  //variable to store the last name
    string StAddress;

    string City;
    string State;
    string Zipcode; 
    string Relation;
    string PhNo;
    int DMonth; //variable to store the month
    int DDay;   //variable to store the day
    int DYear;  //variable to store the year

protected:

    addressType obj1;
    dateType obj2;
    extPersonType obj3;

public:
    addressBookType();
    static int count;
    void loadData(addressBookType *&ptr);

};

//////////class addressType End***
/////////////////////////////////

// IMPLEMENTATION OF "addressBookType" CLASS   //
///////////////// IMP START ////////////////////

void addressBookType::loadData(addressBookType *&ptr){

    ifstream fin;
    ifstream fout;

    string tempName;
    cout<<"Enter file name:"<<endl;


            if(!fin){

                cout<<"Cannot open the image file : "<<endl;
                cout<<"Input Failure"<<endl;
                system("pause");


            }

            else{

                for(int i=0;!fin.eof();i++){

                    fin>>FirstName;
                    fin>>LastName;
                    fin>>DDay;
                    fin>>DMonth;
                    fin>>DYear;
                    getline(fin,StAddress);
                    getline(fin,City);
                    getline(fin,State);
                    fin>>Zipcode;
                    fin>>PhNo;
                    fin>>Relation;

                    cout<<FirstName<<LastName<<DDay<<DMonth<<DYear<<StAddress<<City<<State<<Zipcode<<PhNo<<Relation<<endl;

                }

            }   

}

int main (){

     addressBookType *ptr;
     addressBookType obj;
     ptr=new addressBookType[500];
     obj.loadData(ptr);

     system("pause");
     return(0);
}
#包括
#包括
#包括
#包括
使用名称空间std;
//////////////////////////////“personType”来自D.S Malik课程网站
////////////***班级人员启动
类人形
{
公众:
无效打印()常量;
//函数输出名字和姓氏
//格式为firstName lastName。
void setName(首先是字符串,最后是字符串);
//函数可根据设置firstName和lastName
//对参数进行修改。
//后置条件:firstName=first;lastName=last
字符串getFirstName()常量;
//函数返回第一个名称。
//Postcondition:返回firstName的值。
字符串getLastName()常量;
//函数返回姓氏。
//Postcondition:返回lastName的值。
personType(字符串第一,字符串最后);
//建造师
//根据参数设置firstName和lastName。
//参数的默认值为空字符串。
//后置条件:firstName=first;lastName=last
私人:
string firstName;//用于存储名字的变量
字符串lastName;//用于存储姓氏的变量
};
/////////班长***///////////
//“PersonType”类的实现//
/////////////////IMP启动////////////////////
personType::personType(字符串第一个=,字符串最后一个=){
}
void personType::setName(字符串第一,字符串最后){
firstName=first;
lastName=last;
}
字符串personType::getFirstName()常量{
返回名字;
}
字符串personType::getLastName()常量{
返回姓氏;
}
void personType::print()常量{

cout很明显,您还没有实现
addressBookType
的默认构造函数:

class addressBookType {
//...
    addressBookType();                      //declare constructor
    void loadData(addressBookType *&ptr);   //declare method
};

//missing constructor implementation

void addressBookType::loadData(addressBookType *&ptr){ //implement method
//...
}
要解决此错误,只需添加

addressBookType::addressBookType() { }
请注意,这将把
字符串
成员初始化为空字符串,即对象

addressType obj1;
dateType obj2;
extPersonType obj3;

使用各自的默认构造函数,POD类型将保持未初始化状态。

很明显,您尚未实现
addressBookType的默认构造函数:

class addressBookType {
//...
    addressBookType();                      //declare constructor
    void loadData(addressBookType *&ptr);   //declare method
};

//missing constructor implementation

void addressBookType::loadData(addressBookType *&ptr){ //implement method
//...
}
要解决此错误,只需添加

addressBookType::addressBookType() { }
请注意,这将把
字符串
成员初始化为空字符串,即对象

addressType obj1;
dateType obj2;
extPersonType obj3;
使用各自的默认构造函数,POD类型将保持未初始化状态