passing an array into a constructor

I have this class called Gaus which has these private members

1
2
3
4
5
6
7
8
9
	double *lambda;
	double *sigma;
	double contourC;
	double x;
	double y;
	double z;
	double *centerX;
	double *centerY;
	double *centerZ;


Anyway I have this constructor that has 9 arguments and basically assigns the values to all these members

1
2
3
4
5
6
7
8
9
10
11
12
13
Gaus::Gaus (double lam[], double sig[], double c, double varX, double varY, double varZ, double cenX[], double cenY[], double cenZ[], int varArraySize)
{
	lambda = lam;
	sigma = sig;
	contourC = c;
	x = varX;
	y = varY;
	z = varZ;
	centerX = cenX;
	centerY = cenY;
	centerZ = cenZ;
	dz = varArraySize;
}


However, when I compile the code I get this error message


1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.cpp(11) : error C2440: '=' : cannot convert from 'double' to 'double *'
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.cpp(12) : error C2440: '=' : cannot convert from 'double' to 'double *'
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.cpp(17) : error C2440: '=' : cannot convert from 'double' to 'double *'
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.cpp(18) : error C2440: '=' : cannot convert from 'double' to 'double *'
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.cpp(19) : error C2440: '=' : cannot convert from 'double' to 'double *'


Does anyone know what I'm doing wrong? I need away to initialize 5 variables that are arrays of doubles. However, I don't think I can declare the members as arrays because they have to get initialized. So I made them pointers to doubles
Are you sure you are passing an array? It seems like you are passing a single double value. Can you paste the code where you call the functions? Can you note the lines where the errors occur ?
You have a problem here.

I assume you want to copy the contents of the array parameters into the class members. To do this, you need to know how big the caller's array is. Currently, nothing tells you that. If you know, then you can do this:

1
2
lambda = new double[ size-of-lam-array ];
std::copy( lam, lam + size-of-lam-array, lambda );

Topic archived. No new replies allowed.