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 497021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:44:30+00:00 2026-05-13T05:44:30+00:00

My last question was a mess. I’m getting the wrong output. So here I

  • 0

My last question was a mess. I’m getting the wrong output.

So here I have in my main:

image = QImage(width, height, 32); // 32 Bit
Color amb(0.1,0.1,0.1);
Color difCoef(0.75,0.6,0.22);
Color spec(0.5,0.5,0.5);
double shineExp = 3.0;
Sphere *s = new Sphere(Point(0.0,0.0,-5), 100.0, amb, difCoef, spec, shineExp);
shapes.push_back(s);

Where shapes is vector < Shape * > shapes;

Shape *x = shapes[0];
cout << "Shine" << x->shine << endl;

Prints out zero even though the answer should be 3.0.

The following are my classes:

#include "shape.h"
class Sphere : public Shape
{
    public:
    Point centerPt;
    double radius;
    Color ambient;
    Color dif;
    Color spec;
    double shine;

    Sphere(Point center, double rad, Color amb, Color difCoef, Color specu, double shineVal)
    {
        centerPt = center;
        radius = rad;
        ambient = amb;
        dif = difCoef;
        spec = specu;
        shine = shineVal;
    }

class Shape
{
    public: 
    Shape() {}
    ~Shape(){} 
    Color ambient;
    Color dif;
    Color spec;
    double shine;
    virtual bool checkIntersect(Point p, Point d, Point &temp) = 0; // If intersects, return true else false.
    virtual Point getNormal(Point intPt) = 0; // Get the normal at the point of intersection
    //virtual void printstuff() = 0;

};
  • 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-13T05:44:31+00:00Added an answer on May 13, 2026 at 5:44 am

    The problem is that you’re repeating your variable declarations in the derived class. You don’t need to redeclare variables like double shine, which are already in Shape, in the derived class Sphere. Since Sphere inherits from Shape, all the public member variables in Shape are automatically inherited in Sphere, and do not need to be redeclared. Redeclaring them will result in two different member variables, i.e. Sphere::shine is a totally different variable from Shape::shine.

    Therefore, when you assign a value to Sphere::shine, and then later access an instance of Sphere with a base-class Shape pointer, the value of shine is not going to be what you expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

building on my last question jQuery getting values from multiple selects together I have
My last question was about getting the string representation of an object serialized to
This is a followup to my last question . I now have a byte[]
my last question on pointer cursors. in Html you have a input file tag.
This should be my last question on Jquery Sortable...for a while :) I have
This will be my last question for the evening and a while. I have
In my last question ( here ), I had an issue where I was
In my last question seen here: Sudoku - Region testing I asked how to
this question is partially related to my last question . I have a generic
Sorry if my last question is very similar, but I have another query of

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.