从(long double *)转换为(const double *) [英] Cast from (long double*) to (const double*)

查看:244
本文介绍了从(long double *)转换为(const double *)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何从(long double *)转换为(const double *)


我试过:

const double * Value1 =(const double *)Value2;


编译器不会抱怨,但是当我访问

const double *时实际结果是不正确的。


注意(long double *)是一个指向长双精度数组的指针。

How can I cast from (long double*) to (const double*)

I have tried:
const double* Value1 = (const double*)Value2;

The compiler does not complain but the actual results when I access
the const double* are incorrect.

Note that the (long double*) is a pointer to an array of long doubles.

推荐答案



ferran < FE ***** @ yahoo.com>在消息中写道

news:53 ************************** @ posting.google.c om ...

"ferran" <fe*****@yahoo.com> wrote in message
news:53**************************@posting.google.c om...
如何从(long double *)转换为(const double *)

我试过:
const double * Value1 =(const double *)值2;


你已经回答了自己的问题。

编译器没有抱怨,但是当我访问const时实际结果是double *不正确。


不足为奇。

注意(long double *)是一个指向长双精度数组的指针。
How can I cast from (long double*) to (const double*)

I have tried:
const double* Value1 = (const double*)Value2;

Well you''ve answered your own question.
The compiler does not complain but the actual results when I access
the const double* are incorrect.

Not surprisingly.
Note that the (long double*) is a pointer to an array of long doubles.




我想你要问的问题是如何*将一个长的

双数组转换为一系列双打,投射无益因为你已经发现了




分配新的双打数组并复制长双打的唯一方法

一个接一个地到新阵列。类似


double * Value1 = new double [N];

for(int i = 0; i< N; ++ i)

Value1 [i] = Value2 [i];


john



I think the question you meant to ask is how to I *convert* an array of long
doubles to an array of doubles, casting is not helpful as you have already
found out.

The only way to allocate a new array of doubles and copy the long doubles
over to the new array one by one. Something like

double *Value1 = new double[N];
for (int i = 0; i < N; ++i)
Value1[i] = Value2[i];

john




" ferran" < FE ***** @ yahoo.com>在消息中写道

news:53 ************************** @ posting.google.c om ...

"ferran" <fe*****@yahoo.com> wrote in message
news:53**************************@posting.google.c om...
如何从(long double *)转换为(const double *)

我试过:
const double * Value1 =(const double *)值2;


你已经回答了自己的问题。

编译器没有抱怨,但是当我访问const时实际结果是double *不正确。


不足为奇。

注意(long double *)是一个指向长双精度数组的指针。
How can I cast from (long double*) to (const double*)

I have tried:
const double* Value1 = (const double*)Value2;

Well you''ve answered your own question.
The compiler does not complain but the actual results when I access
the const double* are incorrect.

Not surprisingly.
Note that the (long double*) is a pointer to an array of long doubles.




我想你要问的问题是如何*将一个长的

双数组转换为一系列双打,投射无益因为你已经发现了




分配新的双打数组并复制长双打的唯一方法

一个接一个地到新阵列。类似


double * Value1 = new double [N];

for(int i = 0; i< N; ++ i)

Value1 [i] = Value2 [i];


john



I think the question you meant to ask is how to I *convert* an array of long
doubles to an array of doubles, casting is not helpful as you have already
found out.

The only way to allocate a new array of doubles and copy the long doubles
over to the new array one by one. Something like

double *Value1 = new double[N];
for (int i = 0; i < N; ++i)
Value1[i] = Value2[i];

john


2004年4月10日星期六16:44:44 +0100 in comp.lang.c ++,John Harrison

< jo ************* @ hotmail.com>写道,
On Sat, 10 Apr 2004 16:44:44 +0100 in comp.lang.c++, "John Harrison"
<jo*************@hotmail.com> wrote,
分配新的双打数组并将长双打的唯一方法是逐个复制到新数组。类似

double * Value1 = new double [N];
for(int i = 0; i< N; ++ i)
Value1 [i] = Value2 [i];
The only way to allocate a new array of doubles and copy the long doubles
over to the new array one by one. Something like

double *Value1 = new double[N];
for (int i = 0; i < N; ++i)
Value1[i] = Value2[i];




肯定有比复制一个更好的东西。

std :: vector< double> Value1(Value2,Value2 + N);


或最坏的

std :: copy(Value2,Value2 + N,Value1);


为什么你会为此写一个''for''循环?我不明白。



Surely there is something better than copying one by one.
std::vector<double> Value1( Value2, Value2+N );

Or at the worst
std::copy(Value2, Value2+N, Value1);

Why would you ever write a ''for'' loop for that? I don''t get it.


这篇关于从(long double *)转换为(const double *)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆