Solved

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

Posted on 2004-08-14
10
2,251 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

707 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

22 Experts available now in Live!

Get 1:1 Help Now