我最後的問題是一團糟。我收到錯誤的輸出。關於指針和對象的問題
所以在這裏我有我的主:
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);
凡形狀是矢量<形狀*>形狀;
Shape *x = shapes[0];
cout << "Shine" << x->shine << endl;
打印出零即使答案應該是3.0。
以下是我的課:
#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;
};
謝謝,這樣比過去後一個更好的答案
shine
成員由於我的瘋狂*******問題:d – 2009-12-08 22:24:26