I need some help in tracking down a problem I am having. Attached is a zip file that has a bulk of the files used in this assignment.

I am recieving a compiler error that I do not know where to look for the solution. The IDE shows the error: undefined reference to 'vtable for extPersonType'. I have not seen this error before, that I know of.

----------------------

/* 
 * File:   extPersonType.cpp
 * Created on January 26, 2011, 01:38 AM
 */
#include "extPersonType.h"
//#include "personType.h"
//#include "addressType.h"
#include <iostream>
using namespace std;

void extPersonType::print()const
{
     cout << lastName << firstName << streetAddress << city << state << zipCode << "Birthday" << dMonth << dDay << dYear;
     switch (classification)
        {
         case 'R':
             cout << " friend ";
         case 'A':
             cout << " family ";
         case 'B':
             cout << " business ";
         default:
             cout << "";
        }

}
void extPersonType::setExtPersonType(string last, string first, string address, string cty, string st, string zip, int mon, int day, int year, char classif)
{
    lastName = last;
    firstName = first;
    streetAddress = address;
    city = cty;
    state = st;
    zipCode = zip;
    dMonth = mon;
    dDay = day;
    dYear = year;
    classification = classif;

}
void extPersonType::setClassification(char classif)
{
    classification = classif;
}

void extPersonType::setPhoneNumber(string phone)
{
    phoneNumber = phone;
}

char extPersonType::getClassification()
{
    return classification;
}

string extPersonType::getPhoneNumber()
{
    return phoneNumber;
}

extPersonType::extPersonType() {
}

extPersonType::extPersonType(string last, string first, string address, string cty, string st, string zip, int mon, int day, int year, char classif) {

    lastName = last;
    firstName = first;
    streetAddress = address;
    city = cty;
    state = st;
    zipCode = zip;
    dMonth = mon;
    dDay = day;
    dYear = year;
    classification = classif;
}

-------------------------------------------------






/* 
 * File:   extPersonType.h
 * Created on January 26, 2011, 01:39 AM
 */
#ifndef _EXTPERSONTYPE_H
#define	_EXTPERSONTYPE_H
#include "personType.h"
#include "dateType.h"
#include "addressType.h"

using namespace std;

class extPersonType: public personType, public dateType, public addressType {
public:
    void print()const;
        // print the extPerson Type to console
        // Postcondition: personType.firstName, personType.lastName, addressType.streetAddress, .... to console
    void setExtPersonType(string last, string first, string address, string cty, string st, string zip, int mon, int day, int year, char classif);
        // set elements of ext person type

    void setClassification(char classif);
        //set the classification. A = family, R = friend, B = business
        // postcondition classification

    void setPhoneNumber(string phone);
        //sets the phone number
        //postcondition phoneNumber string

    char getClassification();
        //returns classification

    string getPhoneNumber();
        //returns classification

        extPersonType();
    extPersonType(string last, string first, string address, string cty, string st, string zip, int mon, int day, int year, char classif);
    virtual ~extPersonType();
protected:
    char classification;
    string phoneNumber;

};

#endif	/* _EXTPERSONTYPE_H */

Thanks,

Danni

Recommended Answers

All 9 Replies

Are you sure that every member function has a definition (not just a declaration)?

Yeah, he's missing the destructor definition for extPersonType (not to "Me too" your post, but I was just working on seeing if the whole project would compile)

Yeah, he's missing the destructor definition for extPersonType (not to "Me too" your post, but I was just working on seeing if the whole project would compile)

Hi jonsca: Thanks for helping me with the problem. Do you think is the destructor definition the problem here?


Danni

Are you sure that every member function has a definition (not just a declaration)?

Hi Moschops: Just in case I have the complete work attached here.

Thanks for helping

Danni

I did not trying running your program, but the vtable error is eliminated. See http://stackoverflow.com/questions/4351077/how-when-do-i-use-a-virtual-destructor for corroboration that the change I proposed is necessary.

I read your response and it makes sense.

It is also in a way compiler dependant. For a long winded reason I am using Netbeans IDE which with the GCC++ compiler. In 07 I had VS2005 on a different laptop that I retired. I re-gained access to it and tried to compile it and didn't have this error.

Compounding this is that Netbeans (helpfully??) pre-builds the blank header file with what it thinks is the minimum info. With Visual Studio, a blank page is just that.

From what I can gather in my research the Microsoft compiler is not true ISO c++ while the gcc++ is.
Here is a link that describes this issue:
http://www.daniweb.com/forums/thread114299.html

I do have another question:
From the code below, the getLastName method is:

void extPersonType::getLastName(string& lName)
{
string first;
string last;
personType::getName(first,last);
lName = last;
}

How does this work with respect to passing the last name back to the calling program? From what I can tell the lName is declared as string in the function header. Thus lName is never seen outside the method.

Is lName supposed to be declared in the calling program as public?

Wouldn't declaring the method to return a string (not void) and "returning" the string be better?

Thank you for your time

Danni

This is referred to as passing by reference. No, it does not need to be declared public. Consider an example:

void swap(int a, int b)
{
    int temp = a;
    a = b;
    b = temp;
}

vs. 

void swap2(int & a, int & b)
{
   int temp = a;
   a = b;
   b = temp;

}

In main:

int x=10,y=6;
swap(x,y);
std::cout<<x<<","<<y<<std::endl; //output 10,6 since only copies were swapped

swap2(x,y);
std::cout<<x<<","<<y<<std::endl; //output 6,10 since the actual variables were swapped

So whatever string you send into that getLastName() method is being changed directly.

That being said, you could just return the variable, but if you needed more than one string returned, that wouldn't work.

Thank you very much Jonsca!!

Danni


This is referred to as passing by reference. No, it does not need to be declared public. Consider an example:

void swap(int a, int b)
{
    int temp = a;
    a = b;
    b = temp;
}

vs. 

void swap2(int & a, int & b)
{
   int temp = a;
   a = b;
   b = temp;

}

In main:

int x=10,y=6;
swap(x,y);
std::cout<<x<<","<<y<<std::endl; //output 10,6 since only copies were swapped

swap2(x,y);
std::cout<<x<<","<<y<<std::endl; //output 6,10 since the actual variables were swapped

So whatever string you send into that getLastName() method is being changed directly.

That being said, you could just return the variable, but if you needed more than one string returned, that wouldn't work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.