Solved

error C2440: '=' : cannot convert from 'double' to 'double *'

Posted on 2004-08-14
10
2,269 Views
Last Modified: 2010-05-18
Hi
i am trying to square an array but i get this error ?
Can anyone please tell me how can i get rid of this
 error C2440: '=' : cannot convert from 'double' to 'double *'

// pointer to type "double"
double *S1;
then S1 has some values int he algo.
In the end i am trying to sqaure then i get this error .
this is the line giving errors : SquaredArray = S1[i] * S1[i] ;

iCe
0
Comment
Question by:iceb
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11801851
Please post more code to detect exact error point. Apparently, you are trying to assign a double where you need a pointer to a double.
0
 
LVL 7

Expert Comment

by:JugglerW
ID: 11801906
What is squared array?
If it is also declared as

double* SquaredArray

your expression should be:

SquaredArray[i] = S1[i] * S1[i] ;

0
 
LVL 7

Expert Comment

by:JugglerW
ID: 11801918
This would explain the compiler message:

double* SquaredArray;
...
SquaredArray = S1[i] * S1[i]

Types are:
double* = double

So compiler says that it cannot convert a double ( right side) to a double* (left side)
0
 
LVL 1

Author Comment

by:iceb
ID: 11801930
//JOKER is a specilaised pointer to type "DOUBLE"
   JOKER X1, Y1, Z1;

X1 = (JOKER) calloc(DATA, sizeof(DOUBLE));
Y1 = (JOKER) calloc(DATA, sizeof(DOUBLE));
Z1 = (JOKER) calloc(DATA, sizeof(DOUBLE));
Magnitude( --, --, --, &X1[i]);  This is a function where lots of parameters is being passed . Only the last parameter is shown and is the error giving parameter later in the code.

NOW I AM TRYING to do is square the array containing X[i]
Z[i] = (JOKERL) (X[i] * X[i]) /( Y[i] * Y[i]) ;          ERROR IN THIS LINE

error C2440: '=' : cannot convert from 'double' to 'double *'

thx for the prompt reply.

0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 11801969
What is JOKERL??

if it is double* also, it is a wrong cast. I think you could skip that and it will compile:

Z[i] =  (X[i] * X[i]) /( Y[i] * Y[i]) ;

Regards, Alex
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:iceb
ID: 11802002
JOKERL was a typo. it is JOKER.


NOW I AM TRYING to do is square the array containing X[i]
Z[i] = (JOKER) (X[i] * X[i]) /( Y[i] * Y[i]) ;          ERROR IN THIS LINE

error C2440: '=' : cannot convert from 'double' to 'double *'

thx for the prompt reply.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 11802059
The result of a division of doubles is a double and _NOT_ a double * .

Simply remove the cast (JOKER)

Regards, Alex
0
 
LVL 1

Author Comment

by:iceb
ID: 11802235
thx alex
there is no error now.
Before i close this question can you just explain one thing :
what is cast ?
i always get into problem trying to find out when to use and when not to use.
i am very confused about it.

thx again.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 500 total points
ID: 11802540
if you have

  x = (type)y;

than you try to 'cast' y to type 'type'.

e. g.

       int y = -1;
       unsigned int x = (unsigned int) y;

(x is now 0xffffffff).

In C mostly pointers get casted. For example the result of a call to malloc or calloc is a void pointer (no type). But as you need a pointer to double, int or any other type you have to cast it to the correct type.

In C++ normally you try to avoid casting as it unsafe(e.g. if you are casting a void pointer to a pointer type but the object isn't that type, you may get access  violation). When using 'new' instead of malloc/calloc you got a correct pointer and there is no need on a cast.

Regards, Alex
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 500 total points
ID: 11802547
Your code from above without casts

X1 = new double[DATA];
Y1 = new double[DATA];
Z1 = new double[DATA];

NOW I AM TRYING to do is square the array containing X[i]
for (int i = 0; i < DATA; ++i)
    Z[i] = (X[i] * X[i]) /( Y[i] * Y[i]) ;  

Regards, Alex


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now