类型案例问题 [英] type case problem

查看:57
本文介绍了类型案例问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




你好组,


在我班级的方法中,我在类型案例方面存在以下问题。可以

有人请让我深入了解这个吗?


这个函数返回一个指向指定索引的数组的指针。

请知道包含图像数据的数组。

void * CImageArray :: ElementIndex(long iIndex)const

{

return((unsigned char) *)(void *)m_elements)+(iIndex *

m_ElementSize);


}


考虑一下m_element有一种CMemoryBlock。


****************错误信息************* **


错误C2440:''type cast'':无法从''const class

CMemoryBlock''转换为''void *''

没有可用的用户定义转换运算符可以执行此转换,或者无法调用运算符

执行cl.exe时出错。



我们将非常感谢您的帮助。

谢谢,

amit



Hello group,

In a method of my class I have below problem in terms of type case. Can
somebody please give me insight into this?

This function returns a pointer into the array at the specified index.
Please know that the array containing image data.
void* CImageArray::ElementIndex( long iIndex) const
{
return ((unsigned char*) (void*)m_elements) + ( iIndex *
m_ElementSize);

}

Consider that m_element has a type of CMemoryBlock.

**************** Error message ***************

error C2440: ''type cast'' : cannot convert from ''const class
CMemoryBlock'' to ''void *''
No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
Error executing cl.exe.



Your help will be appreciated greatly.
Thanks,
amit

推荐答案

使用mutable关键字使m_elements变为可变。


Raj

make the m_elements mutable using the mutable keyword.

Raj


amit写道:
amit wrote:
在我的课程方法中,我在类型案例方面存在以下问题。


我认为你的意思是类型演员这里。

这个函数返回一个指向指定索引的数组的指针。
请知道包含图像数据的数组。

void * CImageArray :: ElementIndex (long iIndex)const
{
return((unsigned char *)(void *)m_elements)+(iIndex *
m_ElementSize);

}


不要在C ++中使用C风格的演员表。你不需要它们。

考虑到m_element有一种CMemoryBlock。

****************错误消息***************

错误C2440:''type cast'':无法从''const class
CMemoryBlock'转换为'' 'void *''
In a method of my class I have below problem in terms of type case.
I think you mean type "cast" here.
This function returns a pointer into the array at the specified index.
Please know that the array containing image data.
void* CImageArray::ElementIndex( long iIndex) const
{
return ((unsigned char*) (void*)m_elements) + ( iIndex *
m_ElementSize);

}
Don''t use C-style casts in C++. You don''t need them.
Consider that m_element has a type of CMemoryBlock.

**************** Error message ***************

error C2440: ''type cast'' : cannot convert from ''const class
CMemoryBlock'' to ''void *''




这是因为,ElementIndex函数是const,这意味着CImageArray的

成员是不可变的这个功能。你无法返回

''void *''来获取恒定数据。


你有两种选择:


1)使函数非const:删除末尾的''const''

2)返回指向const的指针:可能''void const *''


无论如何,请使用其中一个C ++类型转换运算符。在这种情况下,

reinterpret_cast:


void const * CImageArray :: ElementIndex(size_t iIndex)const

{

返回reinterpret_cast< unsigned char const *>(m_elements)+ iIndex *

m_ElementSize;

}


Ali



This is because, the ElementIndex function is const, meaning that the
members of CImageArray are non-mutable in this function. You cannot return
''void*'' to constant data.

You have two options:

1) Make the function non-const: remove the ''const'' at the end

2) Return pointer-to-const: probably ''void const *''

In any case, use one of the C++ type conversion operators. In this case,
reinterpret_cast:

void const * CImageArray::ElementIndex(size_t iIndex) const
{
return reinterpret_cast<unsigned char const *>(m_elements) + iIndex *
m_ElementSize;
}

Ali


On Thu,2005年4月14日10:22:21 -0700,amit写道:
On Thu, 14 Apr 2005 10:22:21 -0700, amit wrote:


Hello group,

在我的课程方法中,我在类型案例方面遇到了以下问题。可以
有人请让我深入了解这个吗?

这个函数返回一个指向指定索引的数组的指针。
请知道包含图像数据的数组。
>
void * CImageArray :: ElementIndex(long iIndex)const
{
return((unsigned char *)(void *)m_elements)+(iIndex *
m_ElementSize);

}

考虑到m_element有一种CMemoryBlock。

****************错误消息***************

错误C2440:''type cast'':无法从''const class
CMemoryBlock'转换为'' 'void *''
没有可以执行此转换的用户定义转换运算符,或者无法调用运算符
执行cl.exe时出错。


Hello group,

In a method of my class I have below problem in terms of type case. Can
somebody please give me insight into this?

This function returns a pointer into the array at the specified index.
Please know that the array containing image data.
void* CImageArray::ElementIndex( long iIndex) const
{
return ((unsigned char*) (void*)m_elements) + ( iIndex *
m_ElementSize);

}

Consider that m_element has a type of CMemoryBlock.

**************** Error message ***************

error C2440: ''type cast'' : cannot convert from ''const class
CMemoryBlock'' to ''void *''
No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
Error executing cl.exe.



CMemoryBlock是一个对象,对吗?对于将此对象转换为指针的结果,您的期望是什么?
(它应该指向什么?)


- Jay



CMemoryBlock is an object, correct? What is your expectation as far as teh
result of casting this object to a pointer? (What should it point to?)

- Jay


这篇关于类型案例问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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