Virtual destructor giving me problems );

Hi I'm working on an exercise from a textbook and I am having trouble seeing why I get this error, could someone explain to me the logic behind this?

The relevant code (from emp.h) :

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
class abstr_emp
{
    private:
        std::string fname;
        std::string lname;
        std::string job;
    public:
        abstr_emp(); // default constructor
        abstr_emp(const std::string & fn, const std::string & ln,
                  const std::string & j);
        virtual void ShowAll() const; //labels and showsall data
        virtual void SetAll(); // prompts user for values
        friend std::ostream & operator <<(std::ostream & os, const abstr_emp & e);
        //just diplsays first and last name
        virtual ~abstr_emp() =0; //virtual base class
};
//... more code here
class fink: virtual public abstr_emp
{
    private:
        std::string reportsto;
    protected:
        const std::string ReportsTo() const { return reportsto; }
        std::string & ReportsTo() {return reportsto; }
    public:
        fink();

        fink(const std::string & fn, const std::string & ln,
             const std::string & j, const std::string & rpo);
        fink(const abstr_emp & e, const std::string & rpo);
        fink(const fink & e);
        virtual void ShowAll() const;
        virtual void SetAll();
};


and my emp.cpp code
1
2
3
4
5
6
7
8
9
10
11
12
13
//FINK CLASS - VIRTUAL PUBLIC ABSTR_EMP
fink::fink() : abstr_emp(), reportsto("nobody") {}
fink::fink(const std::string & fn, const std::string & ln,
           const std::string & j, const std::string & rpo)
           : abstr_emp(fn,ln,j) , reportsto(rpo) {}
fink::fink(const abstr_emp & e, const std::string & rpo)
           : abstr_emp(e), reportsto(rpo) {}
fink::fink(const fink & e) : abstr_emp(e), reportsto(e.reportsto) {}
void fink::ShowAll() const
{
    abstr_emp::ShowAll();
    cout << "\nReportsto = " << reportsto;
}


The error appears @ line2 in emp.cpp but is also generated for each constructor I have.


2: undefined reference to `abstr_emp::~abstr_emp()'|
abstract destructors require definitions, otherwise you won't be able to compile.

Add to your program something like

1
2
3
abstr_emp::~abstr_emp()
{
}
That worked, thanks a ton Cubbi!
Topic archived. No new replies allowed.