Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 412875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:07:42+00:00 2026-05-12T18:07:42+00:00

I have to do this for a basic C++ lecture at my university, so

  • 0

I have to do this for a basic C++ lecture at my university, so just to be clear: i would have used the STL if i was allowed to.

The Problem: I have a class named “shape3d” from which i derived the classes “cube” and “sphere”. Now i have to implement “shape3d_stack”, which is meant be able of holding objects of the types “cube” and “sphere”. I used arrays for this and it worked quite well when i tried to do so with a stack of ints. I tried to do it like so:

shape3d_stack.cpp:

15    // more stuff
16    
17        shape3d_stack::shape3d_stack (unsigned size) :
18         array_ (NULL),
19         count_ (0),
20         size_  (size)
21        { array_ = new shape3d[size]; }
22    
23    // more stuff

but, unfortunately, the compiler tells me:

g++ -Wall -O2 -pedantic -I../../UnitTest++/src/ -c shape3d_stack.cpp -o shape3d_stack.o
shape3d_stack.cpp: In constructor ‘shape3d_stack::shape3d_stack(unsigned int)’:
shape3d_stack.cpp:21: error: cannot allocate an object of abstract type ‘shape3d’
shape3d.hpp:10: note:   because the following virtual functions are pure within ‘shape3d’:
shape3d.hpp:16: note:  virtual double shape3d::area() const
shape3d.hpp:17: note:  virtual double shape3d::volume() const

i guess this must be some kind of really ugly design error caused by myself. so how would be the correct way of using all kinds of objects derived from “shape3d” with my stack?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:07:43+00:00Added an answer on May 12, 2026 at 6:07 pm

    You can’t create objects from abstract classes.
    You’ll probably want to create an array of pointers to the abstract class, which is allowed, and fill them with derived instances:

    // declaration somewhere:
    shape3d** array_;
    
    // initalization later:
    array_ = new shape3d*[size];
    
    // fill later, triangle is derived from shape3d:
    array_[0] = new triangle;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 217k
  • Answers 217k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can create a route that has the culture built… May 12, 2026 at 11:26 pm
  • Editorial Team
    Editorial Team added an answer See http://www.opengroup.org/onlinepubs/009695399/functions/scanf.html: Each directive is composed of one of the… May 12, 2026 at 11:26 pm
  • Editorial Team
    Editorial Team added an answer You could simply use the groups to build your filteredDate… May 12, 2026 at 11:26 pm

Related Questions

Alright so I have this C++ image capturing class. I was wondering if I
I had this idea of creating a count down timer, like 01:02, on the
I have a small piece of code that works as a plugin for a
Kind of a basic question but I'm having troubles thinking of a solution so

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.