Home>
code
// Base class
class Bottom
{
        public:
                char esc;
                char kind;
                short x1;
                short y1;
                short x2;
                short y2;
                long foreColor;
                long backColor;
};
// Derived class
class StraightLine: public Bottom
{
        public:
                char lineKind;
                char NOT_USE;
                short startX;
                short startY;
                short endX;
                short end Y;
                //constructor
                StraightLine ();
                // Destructor
                ~ StraightLine ();
};

int main ()
{
    StraightLine * straightine = new StraightLine [2];
    std :: vector<Bottom>bases;// Table to put everything
   // I'm putting data in vector with push_back here and there.
// I'm turning it with an iterator
for (vector<Bottom>:: iterator it = begin (bases);it! = end (bases);++ it)
        {

// Here is where I want to hear
                if (straightine = dynamic_cast<StraightLine *>(it)) {
                        // Here, the function of the derived class is outputting
                }
        }
}

Currently, I am making a program that is training for the company, but I am in trouble because I can not explain the mechanism in the review.
That is where the data of the derived class is put in the vector of the base class, and the data contained in the vector is output while being rotated by the for statement of the iterator later. When I try to output, I can't access the data in the derived class from the iterator.

Therefore, I wrote a process such as assigning vector data to an instance of a newly created derived class in a conditional expression in an if statement and outputting it if it can be assigned.

However, it is said that it is different even if I explain it, and I am in trouble because I can not find related things even if I search for materials.

If i can give a good explanation, please let me know.

c++