C++ Cannot allocate an object of abstract type -


i'm new c++ , know error about. code below.

questions:

  1. i read in post use pointer abstract base class, how do without dynamic allocation?
  2. can using reference instead? tried, didn't work.
  3. can use union {circle c, shape s};? tried, didn't work.

in examples below, circle , square inherit abstract base class shape.

int main() {   std::vector<shape> shapes; //error!   circle c (5);   square s(4);   shapes.push_back(c);   shapes.push_back(s);   return 0; } 

apparently have defined type shape abstract type circle , square types derived shape.

what is;

std::vector<shape*> shapes ; 

and store porters squares , circles shapes vector.

  shapes.push_back (&c) ;   shapes.push_back (&s) ; 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -