Sign in to follow this  
thedustbustr

error: ambiguous conversions from 'Cube *' to 'Object *const '

Recommended Posts

class Object
{public:
	int id;
	Object();
    virtual ~Object();
};

//has an orientation and position in the world
class TangibleObject : public Object
{public: 
    matrix44 localToWorld;
    matrix44 netScale;
    matrix44 netRotation;
    matrix44 netTranslation;

    void scale(const float magnitude);
    void rotate(const vector3& axis, const float degrees);
    void translate(const vector3& v);

    void update(); //update the localToWorld matrix

    TangibleObject();
};

//visible
class DrawableObject : public Object
{public: virtual void draw()=0;};

class Cube : public TangibleObject, public DrawableObject
{
public:
	Cube(unsigned int side);
	void draw();

public:
	// Width x Hieght x Length
	unsigned int w;
	unsigned int h;
	unsigned int l;
};


std::vector<Object*> objects;

Cube* cube=new Cube;
objects.push_back(cube);
drawableObjects.push_back(cube);
error C2594: 'argument' : ambiguous conversions from 'Cube *' to 'Object *const '



I want to add a class derived from a base class to a list of the base class, but the compiler won't let me. How do I do this? I am declaring it as a Cube and not an Object because later on I call some Cube methods. It wouldn't let me cast it to (Object* const) before adding it to the list. Also, is my diamond inheritance going to cause me problems? I'm thinking about combining DrawableObject and TangibleObject. They are seperate right now because the camera is tangible but not visible. Thanks. Dustin [Edited by - thedustbustr on October 15, 2004 11:39:33 AM]

Share this post


Link to post
Share on other sites
You're better off using Interfaces for something like this:



class Object; // Base object
struct ITangible; // handles Orientation, etc
struct IDrawable; // handles Drawing, etc (visibility)
class Cube : public Object, public ITangible, public IDrawable;

std::vector<Object*> objects;
std::vector<IDrawable*> drawableObjects;

Cube* cube = new Cube;
objects.push_back(cube);
drawableObjects.push_back(cube);

Share this post


Link to post
Share on other sites
You're not telling us the whole story here. drawableObjects should be able to take a Object* in just here. Show us the declaration of drawableObjects.

Use virtual inheritance to deal with the diamond issue.

Share this post


Link to post
Share on other sites
C++ doesn't have interfaces. You can fake them with pure virtual classes. However, unlike Java, you can derive from multiple classes, and your base classes can have variables and functions.

Kelly

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this