c++ - Using an abstract class to implement a stack of elements of the derived class -


I have to do this for a basic C ++ lecture in my university, so to be clear: I am a STL Would have used if I had permission.

Problem: I have a class named "size 3D", from which I get the "cube" and "area" squares. Now I have to implement "size 3D stacks", which means that the objects of the "cube" and "spherical" type should be able to hold. I used arrays for this and it worked very well when I tried to do that with an ints stack. I tried to do this:

Size 3__stack CPP:

  15 / more stuff 16 17 size 3d_stack :: size 3d_stack (unsigned size): 18 array (Zero), 19 calculation_ (0), 20 size_ (size) 21 {array_ = new size 3D [size]; } 22 23 // More stuff  

But, unfortunately, the compiler tells me:

  G ++ -Wall-2 -PinkI-i .. /. ./UnitTest++/src/-c Size 3d_stock CPP -A size 3d_stock.o size3d_stack CPP: 'shape3distaka :: shape3d_stack (unsigned int)' in the constructor: size 3d_stack CPP: 21: error: Object Type 'Shape 3D' Shape3d.hpp: 10: Note: Because the following virtual functions are pure within 'Size 3D': Size 3D HPP: 16: Note: Virtual Double Size 3D: Region () const size 3D. HPP: 17: Note: Virtual Double Size 3D:: Quantity () const  

I think it should be of some type of ugly design error due to me. So what would be the correct way to use all types of items obtained from my stack from "shap3d"?

You can not create an object from the object class.
You probably want to create an array of abstract class pointers, which is allowed, and fill them with the generated instance:

  // declaration somewhere: size 3d ** Array_; // Virtualization later: array_ = new size 3D * [size]; // Fill later, the triangle shape is taken from 3D: array_ [0] = new triangle;  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -