Public Group

# Problem with structures

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

## 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-&gt;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&lt;vertices_t*&gt; vVertices, PrimitiveType kPrimitiveType, int iNumVertice, int iNumPrimitives );


And my m_vVertex is defined by.
std::vector&lt;ms3d_vertex_t *&gt;	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&lt;_Ty&gt;' to 'std::vector&lt;_Ty&gt;'
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 on other sites
You can't cast a vector from one type to another like that, even if the template parameters are related like this.

##### Share on other sites
Is there a way I can convert my vector from one type to another?

##### Share on other sites
Quote:
 Original post by TheGangsterIs 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.

• 17
• 10
• 19
• 14
• 19