PootyTanG

The Error

error C2259: 'SphereEntity' : cannot instantiate abstract class
1> due to following members:
1> 'void Entity::render(G3D::RenderDevice *) const' : is abstract
1> : see declaration of 'Entity::render'
1> 'G3D::RealTime Entity::getIntersectionTime(const G3D::Ray &) const' : is abstract
1> : see declaration of 'Entity::getIntersectionTime'

SphereEntity is a declared as a subclass of Entity. Entity is an abstract class with two functions: render and getIntersectionTime. These two purely virtual functions of Entity were implemented in the SphereEntity class.

I receive the error when I try to create an object of SphereEntity.

Any help would be appreciated.

Thanks

CODE
-------------------------
Entity.h
-------------------------
//#ifndef Entity_H
//#define Entity_H

#pragma once
#include <G3DAll.h>
//#include "SphereEntity.h"

// Entity
class Entity {
public:
bool selected;
Entity() : selected(false) {}
virtual ~Entity() {}
virtual void render(RenderDevice*)const = 0;

// Returns amount of time to intersection starting at ray.origin and traveling with ray.velocity.
virtual RealTime getIntersectionTime(const Ray&) const = 0;
};


//#endif
--------------------------------------------------------------------------
-------------------------
SphereEntity.h
-------------------------
//#ifndef SphereEntity_H
//#define SphereEntity_H

#pragma once
#include <G3DAll.h>
#include "Entity.h"

// SphereEntity : subclass of Entity
class SphereEntity: public Entity {

public:
SphereEntity(Color4* _color, Vector3* _position, float _radius);
virtual void render(RenderDevice*);
virtual RealTime getIntersectionTime(const Ray&);

private:
Color4* _color;
Color3* _wireColor;
Vector3* _position;
float _radius;
Sphere *_sphere;
// RenderDevice *renderDevice;
// Vector3 outNormal;
// Vector3 outLocation;
};

//#endif

--------------------------------------------------------------------------
-------------------------
SphereEntity.cpp
-------------------------

#include "SphereEntity.h"

SphereEntity:: SphereEntity(Color4* _color, Vector3* _position, float _radius){
this->_color = _color;
this->_position = _position;
this->_radius = _radius;
_wireColor = new Color3(1,1,1);
}

void SphereEntity::render(RenderDevice* renderDevice){

//this->renderDevice = renderDevice;
*_sphere = Sphere(*_position, _radius);

if(selected == true){
_wireColor = new Color3(1, 1, 1);
renderDevice->setRenderMode(RenderDevice::RENDER_WIREFRAME);
}

Draw:: sphere(*_sphere, renderDevice, *_color, *_wireColor);

renderDevice->setRenderMode(RenderDevice::RENDER_SOLID);
}

RealTime SphereEntity::getIntersectionTime(const Ray& _ray){
double timeForCollision = 0;

timeForCollision = _ray.intersectionTime(*_sphere);

return timeForCollision;
}


Re: Visual C++ Language Frustrating Error - error C2259: cannot instantiate abstract class

higgins427

Make SphereEntity::render() const...

-higgins

---------------------------

// SphereEntity : subclass of Entity
class SphereEntity: public Entity {

public:
SphereEntity(Color4* _color, Vector3* _position, float _radius);
virtual void render(RenderDevice*) const; /// <- make it const, like the base class!
virtual RealTime getIntersectionTime(const Ray&);

private:
Color4* _color;
Color3* _wireColor;
Vector3* _position;
float _radius;
Sphere *_sphere;
// RenderDevice *renderDevice;
// Vector3 outNormal;
// Vector3 outLocation;
};





Re: Visual C++ Language Frustrating Error - error C2259: cannot instantiate abstract class

PootyTanG

Thanks higgins,
The issue was resolved by making the subclass (SphereEntity) function const (ie. not altering the input parameter).