I'm just recently getting into C++ and bashing my head a little bit on the following topic:
I have a Class with 3 double values of which I create the object "supportRefl[4]" as an array.
I now want to return the array in the function "position" of the Class "Scattering" but I can't find a way to that.
It would be greatly appreciated if you can tell me how to do it.
Heres the class:
class Quelle
{
private:
double distanceq;
double elevationq;
double azimuthq;
public:
void SetValue(double distance, double elevation, double azimuth);
double Getd(){return distanceq;}
double Gete(){return elevationq;}
double Geta(){return azimuthq;}
Quelle(double distance=0, double elevation=0, double azimuth=0);
//constructor
~Quelle(); //destructor
};
void Quelle::SetValue(double distance, double elevation, double
azimuth)
{
distanceq = distance;
elevationq = elevation;
azimuthq = azimuth;
}
Quelle::Quelle(double distance, double elevation, double azimuth)
//constructor
{
}
Quelle::~Quelle() // destructor
{
}
and here the function I would like to return the array back into: I red that you'd have a pointer to the first adress of the array but it didn't work at all.
*double Scattering::position(const double &distance, const double &elevation, const double &azimuth, const double &intensity)
{
double intensity_position = intensity * 10 * 5;
m[0] = distance;
m[1] = elevation;
m[2] = azimuth;
double lo[3] = {m[0], m[1]+intensity_position, m[2]-intensity_position}; //zusammenfassen
double ro[3] = {m[0], m[1]+intensity_position, m[2]+intensity_position};
double lu[3] = {m[0], m[1]-intensity_position, m[2]-intensity_position};
double ru[3] = {m[0], m[1]-intensity_position, m[2]+intensity_position};
//create instances
Quelle upperLeft(0,0,0);
Quelle upperRight(0,0,0);
Quelle lowerLeft(0,0,0);
Quelle lowerRight(0,0,0);
const int NUMBER = 4;
Quelle supportRefl[NUMBER];
supportRefl[0].SetValue(lo[0],lo[1],lo[2]);
supportRefl[1].SetValue(ro[0],ro[1],ro[2]);
supportRefl[2].SetValue(lu[0],lu[1],lu[2]);
supportRefl[3].SetValue(ru[0],ru[1],ru[2]);
return supportRefl[];
}
thank you very much for your help, cheers Simon
std::arrayhas value semantics and can be returned normally from a function. Try using anstd::arrayinstead of C arrays.scatteringactually namedQuelle?