c++compiler-errorsabstract-class

invalid new-expression of abstract class type


I am currently writing a raytracer for a university class. In order to load Scenes from files I wrote an sdfloader to read sdf files and create scenes therefor.

if I now want to compile the loader i get the following error:

rc/sdf_loader.cpp: In member function 'void SDFloader::add_shape(std::istringstream&)':
src/sdf_loader.cpp:95:58: error: invalid new-expression of abstract class type 'box'
                                &scene_.materials[mat]));
                                                      ^

I tried to find a solution but failed.

The sdf_loader class looks like the following:

class SDFloader {
  public:
    SDFloader();
    ~SDFloader();

    Scene const& scene() const;
    void read(std::string file);

  private:
    void add_material(std::istringstream&);
    void add_shape(std::istringstream&);
    void add_light(std::istringstream&);
    void add_camera(std::istringstream&);
    void apply_transformation(std::istringstream&);

  private:
    Scene scene_;
};

in my implementation of the sdf loader i wrote the method read():

void SDFloader::add_shape(std::istringstream& iss) {

    std::string name;
    iss >> name;

    if(name == "box") {
      double x1,y1,z1,x2,y2,z2;
      std::string mat;
      iss >> name >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> mat;
      scene_.shapes.insert(new box(point(x1,y1,z1),
                                   point(x2,y2,z2),
                                   name,
                                   &scene_.materials[mat]));
    }

and for every other shape the same calls.

Where is the Problem in my code? I really don't see it

I am using g++-4.9 - std=c++0x to compile and link everything


Solution

  • invalid new-expression of abstract class type 'box'

    There is nothing unclear about the error message. Your class box has at least one member that is not implemented, which means it is abstract. You cannot instantiate an abstract class.

    If this is a bug, fix your box class by implementing the missing member(s).

    If it's by design, derive from box, implement the missing member(s) and use the derived class.