Page 20 of 21 FirstFirst ... 1018192021 LastLast
Results 191 to 200 of 201

Thread: Programming Language

  1. #191
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If we have two classes (let's be imaginative and call them ObjectA and ObjectB), where ObjectB is a subclass of ObjectA:
    Code:
    class ObjectA {
      public:
        ObjectA() {};
        ~ObjectA() {};
    
        void foo() {};
    };
    
    class ObjectB : public ObjectA {
      public:
        ObjectB() : ObjectA() {};
    
        void bar() {};
    };
    It's entirely safe to (up-)cast from ObjectB to ObjectA, since an ObjectB instance will always have all the properties and methods of an ObjectA. ObjectB must have a foo() method; if it doesn't implement its own version it will get ObjectA's default implementation:
    Code:
    ObjectB *oB = new ObjectB;
    ObjectA *oA;
    oA = static_cast<ObjectA*>(oB);
    oA->foo(); // always fine
    However, there is no such guarantee when going (down-casting) the other way: an ObjectA need not implement everything that an ObjectB does, and indeed, in our sample ObjectA lacks ObjectB's bar() method:
    Code:
    ObjectB *oA = new ObjectA;
    ObjectB *oB;
    oB = static_cast<ObjectB*>(oA);
    oB->bar(); // fails!
    Last edited by Twey; 07-03-2007 at 08:43 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  2. #192
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for you post Twey but unluckly I havn't even learnt subclasses, all this time I've been getting used to classes(basics). Do you mind quickly filling me up on all the info of subclasses?

  3. #193
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    "all the info"?
    ...do you not look at tutorials?
    I have no idea how to use subclasses. But if I wanted to, I'm sure there's plenty of info on how to start on google or in any tutorial.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #194
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What dont you understand about what I have already written! I have clearly stated that nearly all the tutorials I do look for end up using some long complicated words...

    Basically I understand what Twey tries to point out(well most of the time ) compared to, well, other sites...

    edit - I realizethat this is abit random but does anyone mind explainng bits to me?
    Last edited by pcbrainbuster; 07-05-2007 at 07:20 PM.

  5. #195
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Then look up the long and complicated words...
    Or learn an easier language.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  6. #196
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Exactly HTML, JavaScript and all those others were guinny pigs...

  7. #197
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I think perhaps tech_support meant easier than English
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #198
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oh shoot, sorry tech_support that was way out of line and I apologise

    edit - By the way guys I actually tried and read and understood everything the was at main level of importancy on this page - http://www.cplusplus.com/doc/tutorial/classes.html - Up to Constructors and Destructors...
    Last edited by pcbrainbuster; 07-07-2007 at 10:28 PM.

  9. #199
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Oh that... Nevermind. I can shoot you later
    I'm sure you meant no harm.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  10. #200
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    edit - By the way guys I actually tried and read and understood everything the was at main level of importancy on this page - http://www.cplusplus.com/doc/tutorial/classes.html - Up to Constructors and Destructors...
    There's nothing scary about constructors and destructors. A constructor is just a special method that's called when the class is created, and a destructor is one that's called when the class is destroyed.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •