• Advertisement
Sign in to follow this  

Problem with structures

This topic is 4436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I've been trying to solve a problem for hours and I can't seem to find the solution to my problem. I am trying to load Milkshape file format using their structure,
struct ms3d_vertex_t : public vertices_t
{
	uint8	flags;				// SELECTED | SELECTED2 | HIDDEN
	float	vertex[3];			//
	char	boneId;				// -1 = no bone
	uint8	referenceCount;		//
};

I've added the last bit which means i am derivating it from another strucutre, an empty one.
struct vertices_t
{
};

Now I have a method which is called my milkshape render.
kRenderer->DrawPrimitive( m_vVertex, TRIANGLE_LIST, m_nNumVertices, m_vVertex.size() );

That kRenderer is a pointer to my render class which can be RenderDX or RenderGL, and will use DrawPrimitive in both. And as I do not want this method to only draw ms3d_vertex_t, I have derivated it from another object (vertices_t). My method is defined by
void DrawPrimitive( std::vector<vertices_t*> vVertices, PrimitiveType kPrimitiveType, int iNumVertice, int iNumPrimitives );

And my m_vVertex is defined by.
std::vector<ms3d_vertex_t *>	m_vVertex

Now what I am trying to do is a very simple thing, I want my structure to be casted as vertices_t and draw it, but I keep getting a weird error and I can't seem to find what the problem is.
error C2664: 'Renderer::DrawPrimitive' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::vector<_Ty>'
        with
        [
            _Ty=ms3d_vertex_t *
        ]
        and
        [
            _Ty=vertices_t *
        ]
        No constructor could take the source type, or constructor overload resolution was ambiguous

Any help would be very appreciated. Thanks in advance for reading my post.

Share this post


Link to post
Share on other sites
Advertisement
You can't cast a vector from one type to another like that, even if the template parameters are related like this.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheGangster
Is there a way I can convert my vector from one type to another?


Not generically. Because consider if you could cast a std::vector<ms3d_vertex_t> to type std::vector<vertices_t>. Then you could do a push_back on that vector with a structure with type vertices_t but not ms3d_vertex_t, and then your std::vector<ms3d_vertex_t> would contain an element that is not a ms3d_vertex_t.

You could come up with a specific function that copies the vector between types, but I would just try to store the data in a std::vector<vertices_t> to start. This is practically the only case where I would recommend upcasting immediately.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement