c++ - Error: object of abstract class "Sphere" not allowed. and Error: no operator "=" matches these operands -


i've been trying resolve error last day or , can't seem work through. it's kind of error fix easy :s tried search similar questions fixes don't apply.

main.c

int main(int argc, char *argv[]){     int width, height;     std::vector<obj*> world;      world.push_back(new sphere(vec(0, 0, -22), 2, vec(0.2, 0.2, 0.2), true));      (...)      return 0; } 

the error found when try create sphere.

relevant classes obj.h

class obj { public:     vec color;     bool culling;      virtual bool intersect(const vec &ray_orig, vec &ray_dir, float *t0 = null, float *t1 = null) = 0; }; 

sphere.h

class sphere: public obj { public:     vec center;                              float radius, radius2;                      sphere(vec center, float radius, vec color, bool culling);      bool intersect(const vec &ray_orig, vec &ray_dir, float *t0 = null, float *t1 = null); }; 

sphere.c

sphere::sphere(vec center, float radius, vec color, bool culling){     this->center = center;     this->radius = radius;     this->color = color;     this->culling = culling; }   bool sphere::intersect(const vec &ray_orig, vec &ray_dir, float *t0 = null, float *t1 = null) {...} 

these second error appears when this->color = color;. not sure if related.

vec simple struct 3 variables.

if need more information i'll add possible.

thank in advance.

jose

edit

sorry delay.

intersect(...) function in obj class. there anyway maintain abstraction since there several objects(sphere,box,...).

as requested here goes definition of vec.h

vec.h

    struct vec {          float x, y, z;          vec() {x = 0, y = 0, z = 0;}         vec(float val) {x = val, y = val, z = val;}         vec(float x_val,float y_val,float z_val) {x = x_val, y = y_val, z = z_val;}         vec(const vec& copy) : x(copy.x), y(copy.y), z(copy.z) { }          vec operator+ (const vec& p) const {             return vec(x + p.x, y + p.y, z + p.z);         }          vec operator- (const vec& p) const {             return vec(x - p.x, y - p.y, z - p.z);         }          vec& operator += (const vec& p) {             x += p.x; y += p.y; z += p.z;             return *this;         }          vec& operator -= (const vec& p) {             x -= p.x; y -= p.y; z -= p.z;             return *this;         }          vec operator* (const float f) const {             return vec(f * x, f * y, f * z);         }          vec& operator*= (const float f) {             x *= f; y *= f; z *= f;             return *this;         }          vec operator/ (const float f) const {             float inv = 1.f / f;             return vec(inv * x, inv * y, inv * z);         }          vec& operator/= (const float f) {             float inv = 1.f / f;             x *= inv; y *= inv; z *= inv;             return *this;         }  vec& operator= (const vec& p) {         x = p.x; y = p.y; z = p.z;         return *this;     }      bool operator== (const vec& p) {         if(x == p.x && y == p.y && z == p.z)             return true;         return false;     }          float length_squared() const {             return x*x + y*y + z*z;         }          float length() const {             return sqrt(length_squared());         }          vec norm() const {             float nor = x * x + y * y + z * z;             if (nor > 0) {                 float invnor = 1 / sqrt(nor);                 (float)x *= invnor, (float)y *= invnor, (float)z *= invnor;             }             return *this;         }          vec cross(const vec&b) {             return vec(y*b.z-z*b.y,z*b.x-x*b.z,x*b.y-y*b.x);         }          float dot(const vec& v) {             return x * v.x + y * v.y + z * v.z;         }       }; 

it seems problem indeed in vec file.

can't find reasoning fix, changing vec struct class fixed problems.

thanks help.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -