473,624 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

type case problem



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::El ementIndex( long iIndex) const
{
return ((unsigned char*) (void*)m_elemen ts) + ( 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

Jul 23 '05 #1
14 1822
make the m_elements mutable using the mutable keyword.

Raj

Jul 23 '05 #2
amit wrote:
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::El ementIndex( long iIndex) const
{
return ((unsigned char*) (void*)m_elemen ts) + ( 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 *'


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_cas t:

void const * CImageArray::El ementIndex(size _t iIndex) const
{
return reinterpret_cas t<unsigned char const *>(m_elements) + iIndex *
m_ElementSize;
}

Ali

Jul 23 '05 #3
On Thu, 14 Apr 2005 10:22:21 -0700, amit wrote:


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::El ementIndex( long iIndex) const
{
return ((unsigned char*) (void*)m_elemen ts) + ( 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 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
Jul 23 '05 #4

I'm going to load a TIF file into an array but every TIF file could
have several pages. CImageArray is a type that I can instantiate an
object for array and CMemoryBlock is a class which should give me
methods like
free(), alloc() and realloc().

Please consider that the application I'm working on is based on libtiff
which is written in C Ansi.

Please let me know if you have any suggestions.

Thanks,
Amit,

Jay Nabonne wrote:
On Thu, 14 Apr 2005 10:22:21 -0700, amit wrote:


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::El ementIndex( long iIndex) const
{
return ((unsigned char*) (void*)m_elemen ts) + ( 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 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


Jul 23 '05 #5

No, mutable didn't hlep. Thanks anyway for your response.

Jul 23 '05 #6

No, mutable didn't hlep. Thanks anyway for your response.

Jul 23 '05 #7

I tried all steps 1 ~ 3 but still complains.

I thought solution 3 would work but it turns out with this:

error C2440: 'reinterpret_ca st' : cannot convert from 'class
suMemBlock' to 'unsigned char'
Conversion requires a constructor or user-defined-conversion
operator, which can't be used by const_cast or reinterpret_cas t
C:\Development\ testing\faxlibc onsole\ImageArr ay.cpp(135) : error C2059:
syntax error : ')'

Jul 23 '05 #8
On Thu, 14 Apr 2005 12:10:09 -0700, amit wrote:

I'm going to load a TIF file into an array but every TIF file could
have several pages. CImageArray is a type that I can instantiate an
object for array and CMemoryBlock is a class which should give me
methods like
free(), alloc() and realloc().

Please consider that the application I'm working on is based on libtiff
which is written in C Ansi.

Please let me know if you have any suggestions.


Then I suspect you need to call some of the methods on the object.

Or at least answer my question about what you expected the cast of the
object to a pointer to accomplish. :)

- Jay
Jul 23 '05 #9

Sorry, about your question:

It should return a pointer into the array at the specified index.

Jay Nabonne wrote:
On Thu, 14 Apr 2005 12:10:09 -0700, amit wrote:

I'm going to load a TIF file into an array but every TIF file could
have several pages. CImageArray is a type that I can instantiate an
object for array and CMemoryBlock is a class which should give me
methods like
free(), alloc() and realloc().

Please consider that the application I'm working on is based on libtiff which is written in C Ansi.

Please let me know if you have any suggestions.

Then I suspect you need to call some of the methods on the object.

Or at least answer my question about what you expected the cast of

the object to a pointer to accomplish. :)

- Jay


Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
4517
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
4
2722
by: wkaras | last post by:
I would like to propose the following changes to the C++ Standard, the goal of which are to provide an improved ability to specify the constraints on type parameters to templates. Let me say from the start that my knowledge of compiler implementation is very limited. Therefore, my suggestions may have to be rejected because they are difficult or impossible to implement. The proposal is based on the concept of "type similarity". Type...
16
4442
by: David Ford | last post by:
I have a macro that I use across the board for freeing ram. I'd like to clean up my code so I don't get these warnings. #define sfree(x) _internal_sfree((void **)&x) #define _internal_sfree(x) ({ if(x && *x) { free(*x); *x=NULL; } }) void somefunction() { char *x = malloc(10); int *y = malloc(10);
0
17771
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico Mariani, performance architect for the Microsoft® .NET runtime and longtime Microsoft developer, mentioned to Dr. GUI in an e-mail conversation recently that a fairly common practice (and one that's, unfortunately, described in some of our...
12
5123
by: Joel Byrd | last post by:
I'm having a little problem with using type-ahead functionality for an auto-suggest box. Sometimes, when I start to type something and the type-ahead shows up, the AJAX will send a request query using the value that *includes* the type-ahead value. In other words, say that I type in "ja" and the first listing that comes up is "jack@test.com". The AJAX part is supposed to send "ja" as one of the query string variables when calling the...
13
4522
by: Fei Liu | last post by:
Hi Group, I've got a problem I couldn't find a good solution. I am working with scientific data files in netCDF format. One of the properties of netCDF data is that the actual type of data is only known at run time. Therefore a lot of template based trick isn't too useful. Considering datafile float x(3) 3.5, 2.5, 8.9 double y(3) 2.7, -2.3, 1.2 int z(3) 5, 2, 3
10
23592
by: kar1107 | last post by:
Hi all, Can the compiler chose the type of an enum to be signed or unsigned int? I thought it must be int; looks like it changes based on the assigned values. Below if I don't initialize FOO_STORE to be, say -10, I get a warning about unsigned comparison and I'm seeing an infinite loop. If I do initialize FOO_STORE = -10, I don't see any warnings. No infinite loop.
2
6574
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} I then determine what object I should call the Persist method on using a switch statement (not very OO). switch (otype)
17
4016
by: The Frog | last post by:
Hello everyone, I am working on an application that can build database objects in MS Access from text files. I suppose you could call it a backup and restore type routine. Accessing the fields, tables, relationships, and indexes is no issue for me via DAO code. The issue I have is that I am not sure which properties are actually necessary / available to set from code for each possible type of field. I have looked fo´r a reference on...
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8348
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2613
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1493
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.