Skip to main content
gamedev.net
🔒 Locked

Using 'new' error

Started by Dannon Feb 2, 2004 at 8:29 PM 4 replies 800+ views
Original Post
Dannon
Dannon
I am trying to use the ''new'' command in C++ rather than using ''malloc'', I''ve been told it replaces ''malloc'' in C++. Anyway, this is the line that is has a problem with. loadRen.pVertex[count] = new CVertex; It is in a for loop so that I can create a new CVertex each loop. This is the error that I am getting: binary ''='' : no operator defined which takes a right-hand operand of type ''class CVertex *'' (or there is no acceptable conversion) I''m sure its probably something simple, but I can''t figure it out. Is there a libary I should be adding? I have: #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> Any ideas? --Dannon
pinacolada
pinacolada
What types are loadRen and pVertex? My guess, from your naming convention, is that you wanted to write this:

loadRen[count].pVertex = new CVertex();

-but even if you meant it the way you did, adding the ()s after "new CVertex" would be an improvement.
krez
krez
i''m just guessing since you didn''t include a lot of code, but is loadRen.pVertex a pointer (i.e. array)? if so, you''ll want to allocate them in one call, such as:
loadRen.pVertex = new CVertex[count]; 


if it is a static array (declared CVertex pVertex[count]), you can''t new them like that because it is already allocated.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Dannon
Dannon
I tried the ()s, but they didn''t seem to make any difference, but that might have solved a problem I would have probably come across soon anyway.

pVertex is a pointer to my CVertex class which has:

class CVertex
{
public:
CVertex();
virtual ~CVertex();

cVector origin;
cVector normal;
cVector texCoord;

};

cVector is another class with x, y, z, h in it.

loadRen is a link to the Class CRender that has the pVertex pointer in, this is in my current class header file and is declared as:

CRender loadRen;

The pVertex pointer is in my CRender class.

What I want is [count] number of CVertex, that is why I think this would be done in this way:

loadRen.pVertex[count] = new CVertex;

My programming skills aren''t brilliant, I think this is what you you want to know though.

--Dannon
pinacolada
pinacolada
ah, a dynamic array? You should totally do what krez wrote.
Dannon
Dannon
Thanks to you both.

I have done what krez has suggested and it worked.

Ah well, lets start working towards the inevitable next problem now.

--Dannon

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.