HI all,
let me explain the problem:
In my simulation I am using two class: particle and Container.
//////////// the outline of particle class/////////////////////
Sphere.h---->[code=cpp]
#ifndef SPHERE_H_
#define SPHERE_H_
Class Particle
{
private:
double x; // position of the particle
double Vx; // velocity of the particle
double _R; // radius of the particle
public:
particle()x(0.0 ),Vx(0.0),_R(0. 0){} //default initialisation
particle(double radius)x(0.0),V x(0.0),_R(radiu s){} // user defined one
// and the rest of the code goes here.
};
#endif
[/code]
In another class named "Container" i need to create an array of particle.
[code=cpp]
#ifndef CONTAINER_H_
#define CONTAINER_H_
#include<vector >
using namespace std;
#include"sphere .h"
class Container
{
private:
vector<particle > HardSphere;
// and the rest of the program part goes here.
};
#endif
[/code]
The problem is that in the "container" i want to have the array of particles with desired radius say 1.0. But i always find it invokes the default constructor which set radius to zero. Of course latter on i can run a do loop to set the radius to a desired value. But i was wondering if there is any other way to invoke the different particle constructor from the default one as shown in the particle class. Or using the do loop is the only way.
thank you
anupam
let me explain the problem:
In my simulation I am using two class: particle and Container.
//////////// the outline of particle class/////////////////////
Sphere.h---->[code=cpp]
#ifndef SPHERE_H_
#define SPHERE_H_
Class Particle
{
private:
double x; // position of the particle
double Vx; // velocity of the particle
double _R; // radius of the particle
public:
particle()x(0.0 ),Vx(0.0),_R(0. 0){} //default initialisation
particle(double radius)x(0.0),V x(0.0),_R(radiu s){} // user defined one
// and the rest of the code goes here.
};
#endif
[/code]
In another class named "Container" i need to create an array of particle.
[code=cpp]
#ifndef CONTAINER_H_
#define CONTAINER_H_
#include<vector >
using namespace std;
#include"sphere .h"
class Container
{
private:
vector<particle > HardSphere;
// and the rest of the program part goes here.
};
#endif
[/code]
The problem is that in the "container" i want to have the array of particles with desired radius say 1.0. But i always find it invokes the default constructor which set radius to zero. Of course latter on i can run a do loop to set the radius to a desired value. But i was wondering if there is any other way to invoke the different particle constructor from the default one as shown in the particle class. Or using the do loop is the only way.
thank you
anupam
Comment