From: plambert@sml.cs.psu.edu (Paul  Lambert)
Subject: Need more help, PLEASE, PLEASE, PLEASE!!!!
Organization: Penn State Computer Science
Date: Thu, 16 Apr 1992 20:31:34 GMT

HELP again!

I know I've been pestering a lot of people, but _NONE_ of the advice I've been
given seems to work.  I'm pretty sure I'm not just being stupid--though it is
a distinct possibility :-).

I have an abstract base class, an a derived class.  I need to have the following
pure virtual operators overloaded:

operator=, operator==, operator<, operator>

I got the operator= to work OK--it was easy, since it's not inherited.

Now, the operator== seems to be working just fine.  It's the operator< and
the operator> that don't work.  No matter how I define them, I get some sort
of error message.

I have them defined EXACTLY the way I see them in every book I have access to
(The C++ Workbook; The Annotated C++ Reference Manual; and Turbo C/C++).
I'm using g++.

The problem is this section of code:

---

#include <stdio.h>
#include <string.h>

class SortableObject {
        public:
        SortableObject& operator=(const SortableObject&) ;
        int operator==(const SortableObject&) ;
        virtual int operator<(const SortableObject&) = 0;
        virtual int operator>(const SortableObject&) = 0;
};

class studentRecord : public SortableObject {
        static int howToSort ; // 1=name, 2=major, 3=gpa

        char name[26];
        char major[6];
        float gpa;

public:

//      define the required operator= function:
        studentRecord& operator=(const studentRecord & stdrec) {
                strcpy(name, stdrec.name);
                strcpy(major, stdrec.major);
                gpa = stdrec.gpa;
                return *this;
        }

//      define the required operator== function:
        int operator==(const studentRecord & stdrec) {
                return(strcmp(name, stdrec.name)==0);
        }

//      define the required operator< function:
        virtual int operator<(const studentRecord & stdrec) {
                if (howToSort==1)
                        return((strcmp(name,stdrec.name)<0));
                else if (howToSort==2)
                        return (strcmp(major,stdrec.major)<0);
                else
                        return(gpa>stdrec.gpa);
        }

//      define the required operator> function:
        virtual int operator>(const studentRecord & stdrec) {
printf("Comparing >:\n"); printRec(); stdrec.printRec();
                if (howToSort==1)
                        return(strcmp(name,stdrec.name)>0);
                else if (howToSort==2)
                        return (strcmp(major,stdrec.major)>0);
                else
                        return(gpa<stdrec.gpa);
        }

};

---

It gives me this error message:

test.c: In function int main ():
test.c:346: cannot allocate an object of type `studentRecord'
test.c:346: since the following virtual functions are abstract:
test.c:10: int SortableObject::operator < (const class SortableObject &)
test.c:11: int SortableObject::operator > (const class SortableObject &)
test.c:350: cannot allocate an object of type `studentRecord'
test.c:350: since type `studentRecord' has abstract virtual functions
test.c:353: cannot allocate an object of type `studentRecord'
test.c:353: since type `studentRecord' has abstract virtual functions

---

Many people had told me to drop the virtual declarations in studentRecord;
that doesn't work.  It gives me the same message.

If I drop _all_ of the virtual declarations (both the virtual in the student-
Record, and the pure virtual in the SortableObject), it gives me:

ld: bad string table size in /depot/gnu/lib/gcc-ccrt0.o


WHAT CAN I DO??????????

This project was due a LONG time ago, and I have another due TONIGHT!  Which I
haven't even started yet!  I CANNOT get this !@#$%^&*() thing to work!

PLEASE, PLEASE, PLEASE, if you can, help me!!!!

--Paul

--
-------------------------------------------------------------------------------
plambert@psuvm.psu.edu, plambert@endor.cs.psu.edu, or just plambert@cs.psu.edu