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 14 1822
make the m_elements mutable using the mutable keyword.
Raj
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
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
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
No, mutable didn't hlep. Thanks anyway for your response.
No, mutable didn't hlep. Thanks anyway for your response.
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 : ')'
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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...
|
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);
|
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...
|
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...
| |
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
|
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.
|
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)
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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
| |
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...
| |