HELP!!! inheritance and other stuff

This is a discussion on HELP!!! inheritance and other stuff within the C++ Programming forums, part of the General Programming Boards category; I need to finish this project by tomorrow night and i am nowhere near done, so the SOS is officially ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    43

    Exclamation HELP!!! inheritance and other stuff

    I need to finish this project by tomorrow night and i am nowhere near done, so the SOS is officially sent, someone please help me, code is attached and project description can be found here:
    http://www.cs.umbc.edu/courses/under....projfour.html
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    43

    update

    ok, i got the inheritance part working (adding public : Number to each .h file) so dont worry about that, if anyone can get my multiplication overload in fixedpoint working that would be great, it would be even greater if someone got the division one working in the same function

    also any of the functions that return pointers (scale, square, and raise) in any of the classes, i cant get them working, if anyone can great, im pretty sure the rest of this project is fine, my big problem is the overloads in fixed point, i cant seem to get my algorythm to work right

    also i dont think my exception handler works right, it throws and catches just fine but the data it throws to say which function and class the error happened in dosnt set or something, ill prob figure that out in the next 10 minutes or so

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    43

    yet another update

    i lied in the last one, the inheritance stuff sint working, i can compile each file but i cant link them all, tons o errors

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    I had a look at your code. Some points -

    1. Default arguments should be specified in the declaration, not the definition.

    2. If you don't override virtual methods of abstract classes then the derived classes themselves are abstract, so you can't create an instance of them.

    3. If you are deriving a class, make sure that the base class declaration is visible to the derived class.

    There are other errors, but these should be relatively easy to fix once you've dealt with the above.
    zen

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    what do you mean by default arguments

    in a new version of the code i included number.h in all of the derived class .h files, so i think that should solve the third one.
    and im not sure what you mean in the second one at all. i thought i was overridding them...actually i think i may know, ill get back to you in a bit

  6. #6
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Default args -

    class a
    {
    void foo(int i =0);//here
    };

    void a::foo(int i)//not here
    {
    //do stuff
    }


    The problem with your overriding is that you're changing the return types. The compiler can't find the definitions for these functions, so is treating all your classes as abstract.

    Since you're using polymorphism you should only be explicitly using Number pointers. Your overloaded functions are returning pointers to Rational objects and FixedPoint objects when they can and should return pointers to Number objects(and then the vtable will resolve any function calls). Also you're using a Rational pointer in main (rat7), when you only need a Number pointer.
    zen

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    43

    another update

    i changed some stuff around, seems i only have one very annoying error at the moment, and im still not sure what you ment about the shared functions
    Attached Files Attached Files

  8. #8
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    seems i only have one very annoying error at the moment
    I got 130 plus. Your code is now missing implementation for -

    FixedPoint::raise();
    FixedPoint::magnitude();
    Complex::magnitude();

    You need to specify the namespace for functions/objects your files are using.

    Your base class virtual destructor shouldn't be pure.

    You should be returning Number* everywhere in your code where you are presently returning Complex*, FixedPoint*, and Rational*.
    zen

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    43

    blah

    base class destructor cant be non pure, my dumbass prof said it should be in his description and we cant change that

    I cant get rid of the destructor related errors, even if i do make it non pure virtual

    and i tried returning a number pointer in the functions but got more errors

  10. #10
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    base class destructor cant be non pure, my dumbass prof said it should be in his description and we cant change that
    Then you'll still have to provide an empty implementation for it. Ask your dumbass professor why he needs it to be pure.

    and i tried returning a number pointer in the functions but got more errors
    I don't know what to suggest without you posting your code or errors, but I've had your code running(with placeholders) so this should work.
    zen

  11. #11
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    here are my errors

    mak: Command not found.
    linux1[38]% make
    /usr/local/bin/g++ -oproj4 -f proj4.o Rational.o Complex.o FixedPoint.o DivideBy
    Zero.o
    Rational.o: In function `Rational::Rational(int, int)':
    Rational.o(.text+0x18a): undefined reference to `Number::~Number(void)'
    Rational.o: In function `Rational::~Rational(void)':
    Rational.o(.text+0x1c0): undefined reference to `Number::~Number(void)'
    Rational.o: In function `Rational::Rational(Rational const &)':
    Rational.o(.Rational::gnu.linkonce.t.(Rational const &)+0x44): undefined referen
    ce to `Number::~Number(void)'
    Complex.o: In function `Complex::Complex(float, float)':
    Complex.o(.text+0x3a): undefined reference to `Number::~Number(void)'
    Complex.o: In function `Complex::~Complex(void)':
    Complex.o(.text+0x70): undefined reference to `Number::~Number(void)'
    Complex.o(.Complex::gnu.linkonce.t.(Complex const &)+0x44): more undefined refer
    ences to `Number::~Number(void)' follow
    collect2: ld returned 1 exit status
    make: *** [proj4] Error 1
    linux1[39]%

    i tried making the destructor non pure virtual...but i dont think i can implement it, if there is a number.cpp file included he will ignore it, i sent him an e-mail but if i know him ill just get a sarcasting "your an idiot" type response back, just like you get if you ask a question in class...yeesh...
    anyway, the previous version of code i posted is almost up to date, i just added some implementation for the functions that were missing it, far as i can tell from the errors the destructor thing is the only problem

  12. #12
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    There's no way around the destructor implementation. You'll either have to put it in it's own file or try something like this -

    virtual ~Number ( )=0{}

    You can't declare a destructor without providing an implementation, which makes pure virtual destructors pointless unless they are the only thing that is forcing the class to be abstract.
    zen

  13. #13
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    yeah, i tried doing it that way already but it didnt work, how did you get it to work?

  14. #14
    Registered User
    Join Date
    Nov 2001
    Posts
    43
    i respectully withdraw this post, i got it working, thank you so much zen, you helped a lot...once i get this thing out of the way i plan to surf around this message board and help as many people as i can =)
    you guys are the best!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21