Skip to main content
gamedev.net
🔒 Locked

An interesting C++ problem...

Started by Moe Apr 9, 2001 at 10:11 PM 5 replies 650+ views
Original Post
Moe
Moe
I have run into a problem with my code. In peticular the code for my particle engine. I have a class for the particle, a class for a particle ID (a way to keep track of the different particle effects that are going on all at once), and a class with member functions that control the particle effects. Here is the class for the particle:
  
//the particle class that makes up a particle

class PARTICLE
{
public:
	D3DXVECTOR3 current_position;	//current position of the particle

	D3DXVECTOR3 previous_position;	//last position of the particle - useful for stretching

									//the particle for rain-like effects

	D3DXVECTOR3 velocity;			//velocity of the particle

	float size;						//width/height when the particles are square

	int type;						//the type of the particle - smoke, rain, dust, etc

	int energy;						//the energy of the particle - between 0 and 100

	
};
  
Here is the class for the particle ID:
  
//the particle effect ID class.  it is used to identify which 

//particle effect to update or destroy

class ParticleEffectID
{
public:
	PARTICLE *array;		//pointer to an array of particles - number determined when

							//CreateParticleEffect is use

	int NumberOfParticles;	//number of particles in the array

	int ParticleType;		//the particle type - rain, sparks, etc

	float Position;	//the position of the starting point


};
  
And last but not least, the class for the particle management:
  
//the particle manager class that keeps track of arrays of particle for effects

//and updates them depending on what type of effect it is.

class ParticleManager
{
public:
	

	static bool CreateParticleEffect(ParticleEffectID Id, int NumOfParticles, 
								int ParticleEffectType, float EffectPosition);
	static bool UpdateParticleEffect(ParticleEffectID Id);
	static bool DestroyParticleEffect(ParticleEffectID Id);
};
  
Now the problem is that I can''t get things to compile. I want to have a pointer passed to the CreateParticleEffect() functions and the DestroyParticleEffect() functions so that they can allocate and de-allocate memory using new and delete. I seem to be getting 1 error message:
  
error C2664: ''__thiscall PARTICLE::PARTICLE(const class PARTICLE &)'' : cannot convert parameter 1 from ''int'' to ''const class PARTICLE &''
  
I am really having trouble figuring this out. Can someone lend me a hand?
Grib
Grib
I would need to see the line where this error occurs, and how you
are constucting particles.

PARTICLE(const particle &) is a copy ctor, so it may
be implied. You could be doing something like array[0]=1 or if
you have a function that the compiler hasn't seen yet it assumes
the function returns an int, that could result from something
like particle f=GenPartcle(); Note: misspelling (can you guess
this gets me a lot)

You also may be looking at trouble as the create/destroy
methods of the manager are static, thus they have no way to add
a particleID to a list to manage. They also are taking copies of
particleID's, thus they have no way to change them.

1. Get particle to work
2. Get ParticleID to work, you may want to rename this to
ParticleList or ParticleSet or something, they don't look
like id's
3. Then look into managing multiple ParticleSet's.

Keep At It!


Edited by - Grib on April 10, 2001 1:36:15 AM

Edited by - Grib on April 10, 2001 1:41:01 AM
Moe
Moe
Thanks for the inspiration!

I call it a particleID because it tells what particle effect that is being changed. It is kind of like the lights in DirectX8. They just have a single digit between 1 and 8 for each light that is created. I hope that you understand it.

I will be sure to post some extra info when I get home.
Moe
Moe
The error is happening on this line:
  
Id.array = new PARTICLE(NumOfParticles);

Does that help any?
HellRiZZer
HellRiZZer
Let me just TRY to explain, because I''m doing C++ for 3 months only..
Ok, as I was told, the new operator return pointer to the newly created thing, e.g
MyParticle = new PARTICLE;
returns to MyParticle the address of particle.
What you are saying, MyParticle = new PARTICLE(NumOfParticles);
means that a single MyParticle structure have to have pointers to all newly created PARTICLE(s)(NumOfParticles);
How about you go:
for(int G=0;G{
MyParticle(G)= new PARTICLE;
}
and i think you can pass pass params to the constructor....
Another thing, is if you got a pre-created array of MyParticle(s), say MyParticle(5) and you want to update it, or re-create, then you can go:
for(intG=0;G{
MyParticle(G)=new Particle;
}
still it''s the same as before...
If you want, reply to me, and i''ll send ya my version of particle system and it''s controlling..
Also tell me how do you operate with VECTORs, I still can''t get it.. )
Cya!
arunvb
arunvb
Id.array = new PARTICLE(NumOfParticles);

With the above statement DOES NOT try to create a array of PARTICLE. Instead it looks for the constructor

PARTICLE (int)

as you are passing an int. As it does not find a constructor with such an argument, it takes the default copy constructor (Note that every class gets a default copy constructor and copy assignment operator which do memberwise copy). The default copy constructor has the prototype:

PARTICLE (const PARTICLE&);

It tries to execute the statement with the copy constructor and it is not able to convert NumOfParticles to const PARTICLE&. This is where you get the compiler error.

To create an array of particles, use square brackets as below:

Id.array = new PARTICLE[NumOfParticles];

Hope this solves you problem.

Arun

Moe
Moe
Yeah, sorry for plastering the message boards for such a stupid thing. It was just that I was using round brackets when I should have been using square brackets. Sorry!

Topic Locked

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

Sign in to reply to this topic.