Thread: Question

  1. #1
    Registered User
    Join Date
    Jan 2019
    Posts
    1

    Question

    how I can use Override Specifier (link); Lambda function (link); List Initialization (link); inside my code:

    Code:
    #include <vector>
    class Shape
    {
    public:
    virtual void display() = 0;
    };
    class Rectangle : public Shape
    {
    public:
    virtual void display()
    {
    // Implementation, not relevant
    }
    };
    int main(int argc, char[] argv)
    {
    std::vector<Shape*> shapeList;
    shapeList.push_back(new Rectangle);
    shapeList.push_back(new Rectangle);
    shapeList.push_back(new Rectangle);
    shapeList.push_back(new Rectangle);
    shapeList.push_back(new Rectangle);
    shapeList.push_back(new Rectangle);
    for (auto shapeList.begin(); it != shapeList.end(); it++)
    {
    (*it)->display();
    }
    return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think it would be better to use features because they are useful for what you are trying to do, rather than because they exist.

    In your case, the override specifier is useful because you are indeed overriding a virtual function. For the other two, what do you want to do that you think you need them? Perhaps a lambda function will come in handy if you're trying to print with a generic algorithm and a callback, but here the for loop is fine.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-25-2014, 05:41 PM
  2. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  3. *szString = things question/memory question
    By Jang in forum C Programming
    Replies: 3
    Last Post: 01-20-2011, 04:59 AM
  4. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  5. Self regiserting DLLs question and libraries question.
    By ApocalypticTime in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2003, 02:02 PM

Tags for this Thread