Calling constructor of the base class of a derived class..

This is a discussion on Calling constructor of the base class of a derived class.. within the C++ Programming forums, part of the General Programming Boards category; Hey all, I'm starting to use more OOP techniques in my programs (I used the basics at one point then ...

  1. #1
    CaptainPenguin
    Guest

    Calling constructor of the base class of a derived class..

    Hey all, I'm starting to use more OOP techniques in my programs (I used the basics at one point then stopped using it so I wouldn't confuse my teacher), but I can't remember a lot of the advanced inheritance techniques.

    I've read up on most of it, but it was awhile ago and since I never used it, I never retained it.

    Anyways, I'm writing a graphical app in SDL where each object on the screen is it's own class derived from the base class, Object. (Which I think could be made an abstract class or something? I can't remember!). The constructor of the Object class sets the screen on which the object is drawn.

    How do I call it when I create derived objects?

    Also, if someone could provide a link with a quick tutorial or refresher on inheritance, I'd appreciate it! (I can't remember anything about virtual functions, abstract?, contaiment, etc... and the book I have is very wordy)

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    doh!

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    if your base class is Object and class A inherits from Object, then creating an instance of A will automatically call the Object constructor followed by the A constructor. Destructors will run in the reverse order. hope that helps...

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    Originally posted by Perspective
    if your base class is Object and class A inherits from Object, then creating an instance of A will automatically call the Object constructor followed by the A constructor. Destructors will run in the reverse order. hope that helps...
    But if the constructor of Object takes a value?

  5. #5
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Is this what you want to do?

    Code:
    class myderivedexception : public exception {
    public:
        myderivedexception(const char* what_arg) : exception(what_arg) {}
    };
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    Originally posted by IfYouSaySo
    Is this what you want to do?

    Code:
    class myderivedexception : public exception {
    public:
        myderivedexception(const char* what_arg) : exception(what_arg) {}
    };
    it appears to be, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 06-20-2008, 03:41 AM
  2. Virtual base class
    By George2 in forum C++ Programming
    Replies: 7
    Last Post: 03-14-2008, 08:45 AM
  3. Calling Base Class Operators
    By pianorain in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2005, 10:53 AM
  4. base and derived class
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 12-12-2001, 03:11 PM
  5. Replies: 1
    Last Post: 11-27-2001, 01:07 PM

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