Hi, This code I inherited worked under VC7 now fails under VC8 with error:
error C2664: 'memcpy' : cannot convert parameter 1 from
'std::_Vector_iterator<_Ty,_Alloc>' to 'void *'
vector <png_color> vPalette;
..
..
..
memcpy(vPalette.begin(), palette, num_palette * sizeof png_color);
png_color is part of the PNG graphics library so I can't change that.
So, what is the best way to substitute the memcpy()?
Thanks 8 3130
"Jack" <te**@test.com> schrieb im Newsbeitrag news:zM********************@pipex.net... Hi, This code I inherited worked under VC7 now fails under VC8 with error: error C2664: 'memcpy' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *' vector <png_color> vPalette; . . . memcpy(vPalette.begin(), palette, num_palette * sizeof png_color); png_color is part of the PNG graphics library so I can't change that. So, what is the best way to substitute the memcpy()?
First of all you should be greatful that the new compiler has found such a nasty bug in that code.
Basically you should replace that memcpy with a loop that assigns a new value to each element of the vector. Depending on what palette, num_palette etc. are std::copy or some other function from algorithm might be usefull.
HTH
Heinz
Jack wrote: Hi, This code I inherited worked under VC7 now fails under VC8 with error: error C2664: 'memcpy' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *' vector <png_color> vPalette; . . . memcpy(vPalette.begin(), palette, num_palette * sizeof png_color);
png_color is part of the PNG graphics library so I can't change that. So, what is the best way to substitute the memcpy()?
It looks like you've fallen foul of the fact that vector iterators
*can* be implemented as pure pointers, but they need not be. To avoid
falling into this trap again, never assume implementation details like
that. begin() returns an iterator so use it where an iterator is
expected. Pretend you don't know that internally that iterator *might*
be a pointer.
You haven't shown full code, so I'm going to assume the following:
palette is an array of png_color objects
the size of the array palette is num_palette
the size of the vector vPalette is >= num_palette
std::copy(palette, palette + num_palette, vPalette.begin());
should do what you want.
Gavin Deane
Jack wrote: Hi, This code I inherited worked under VC7 now fails under VC8 with error: error C2664: 'memcpy' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *' vector <png_color> vPalette; . . . memcpy(vPalette.begin(), palette, num_palette * sizeof png_color);
png_color is part of the PNG graphics library so I can't change that. So, what is the best way to substitute the memcpy()?
Thanks
as Heinz pointed out you might use std::assign
hth
Klaus
Jack wrote: Hi, This code I inherited worked under VC7 now fails under VC8 with error: error C2664: 'memcpy' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *'
vector <png_color> vPalette; . memcpy(vPalette.begin(), palette, num_palette * sizeof png_color);
png_color is part of the PNG graphics library so I can't change that. So, what is the best way to substitute the memcpy()?
std::copy(pallete, pallete + num_palette, vPalette.begin());
HTH,
Michiel Salters.
"Gavin Deane" <de*********@hotmail.com> wrote in message
news:11*********************@e56g2000cwe.googlegro ups.com... Jack wrote: Hi, This code I inherited worked under VC7 now fails under VC8 with error: error C2664: 'memcpy' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *' vector <png_color> vPalette; . . . memcpy(vPalette.begin(), palette, num_palette * sizeof png_color);
png_color is part of the PNG graphics library so I can't change that. So, what is the best way to substitute the memcpy()?
It looks like you've fallen foul of the fact that vector iterators *can* be implemented as pure pointers, but they need not be. To avoid falling into this trap again, never assume implementation details like that. begin() returns an iterator so use it where an iterator is expected. Pretend you don't know that internally that iterator *might* be a pointer.
You haven't shown full code, so I'm going to assume the following: palette is an array of png_color objects the size of the array palette is num_palette the size of the vector vPalette is >= num_palette
std::copy(palette, palette + num_palette, vPalette.begin());
should do what you want.
Thanks, seems to work - compiles anyway :) .
Is there a similar std substitution for memset or must I step through as
Heinz suggested? ( I don' really know the std library)
memset(pV, 0, nPal * sizeof png_color);
fails with the same error.
"Jack" <te**@test.com> wrote in message
news:kc********************@pipex.net... "Gavin Deane" <de*********@hotmail.com> wrote in message news:11*********************@e56g2000cwe.googlegro ups.com... Jack wrote: Hi, This code I inherited worked under VC7 now fails under VC8 with error: error C2664: 'memcpy' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *' vector <png_color> vPalette; . . . memcpy(vPalette.begin(), palette, num_palette * sizeof png_color);
png_color is part of the PNG graphics library so I can't change that. So, what is the best way to substitute the memcpy()?
It looks like you've fallen foul of the fact that vector iterators *can* be implemented as pure pointers, but they need not be. To avoid falling into this trap again, never assume implementation details like that. begin() returns an iterator so use it where an iterator is expected. Pretend you don't know that internally that iterator *might* be a pointer.
You haven't shown full code, so I'm going to assume the following: palette is an array of png_color objects the size of the array palette is num_palette the size of the vector vPalette is >= num_palette
std::copy(palette, palette + num_palette, vPalette.begin());
should do what you want.
Thanks, seems to work - compiles anyway :) .
Is there a similar std substitution for memset or must I step through as Heinz suggested? ( I don' really know the std library) memset(pV, 0, nPal * sizeof png_color);
Should read:
memset(vPalette.begin(), 0, nPal * sizeof png_color);
"Jack" <te**@test.com> wrote in message
news:kc********************@pipex.net... "Gavin Deane" <de*********@hotmail.com> wrote in message news:11*********************@e56g2000cwe.googlegro ups.com... Jack wrote: Hi, This code I inherited worked under VC7 now fails under VC8 with error: error C2664: 'memcpy' : cannot convert parameter 1 from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *' vector <png_color> vPalette; . . . memcpy(vPalette.begin(), palette, num_palette * sizeof png_color);
png_color is part of the PNG graphics library so I can't change that. So, what is the best way to substitute the memcpy()?
It looks like you've fallen foul of the fact that vector iterators *can* be implemented as pure pointers, but they need not be. To avoid falling into this trap again, never assume implementation details like that. begin() returns an iterator so use it where an iterator is expected. Pretend you don't know that internally that iterator *might* be a pointer.
You haven't shown full code, so I'm going to assume the following: palette is an array of png_color objects the size of the array palette is num_palette the size of the vector vPalette is >= num_palette
std::copy(palette, palette + num_palette, vPalette.begin());
should do what you want.
Thanks, seems to work - compiles anyway :) .
Is there a similar std substitution for memset or must I step through as Heinz suggested? ( I don' really know the std library) memset(pV, 0, nPal * sizeof png_color);
Should read:
memset(vPalette.begin(), 0, nPal * sizeof png_color);
Jack wrote: "Jack" <te**@test.com> wrote in message Is there a similar std substitution for memset or must I step through as Heinz suggested? ( I don' really know the std library)
Get yourself a copy of this http://www.josuttis.com/libbook/
It widely recommended and worth it's weight in gold.
memset(pV, 0, nPal * sizeof png_color);
Should read: memset(vPalette.begin(), 0, nPal * sizeof png_color);
Not quite, because memset directly sets the values of individual bytes
of memory without caring whether those bytes values make sense for the
type of data. But you should avoid that sort of low level operation
unless you absolutely need it. Try
std::fill_n(vPalette.begin(), nPal, png_color());
to fill the first nPal elements of the vector with default-constructed
png_color objects.
Gavin Deane This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Randell D. |
last post by:
Folks,
I have a number of years with HP Unix and Linux but I've never dipped my
toes in to Perl - I currently have SuSE 8.1 at home and am using webmin
(www.webmin.com) to update Perl 5.8.0-45...
|
by: Jason |
last post by:
Hi.
I have a structure that was used in a previous iteration of a loop, and I
want to clear out all the structures values that the previous iteration
assigned without assigning every variable to...
|
by: Lues |
last post by:
Hi,
I'm trying to protect some data in tables with encription (you know why,
don't you ;))
I must confess that I'm not very expirienced in writing code, especially
encription code.
Can any...
|
by: Daveyk0 |
last post by:
Hello there,
I have a front end database that I have recently made very many changes
to to allow off-line use. I keep copies of the databases on my hard
drive and link to them rather than the...
|
by: Mark Richards |
last post by:
I've been programming for many years, but have only recently taken a
deep "C" dive (bad pun, i know) and need a lot of explanation from an
expert. My questions center around those mysterious...
|
by: Roubles |
last post by:
Hi All,
Quick question; what is the difference between initializing and
clearing a structure like this:
mystruct_t a = {0};
and initializing and clearing it like this:
|
by: Lappis |
last post by:
I created a handler for evenlog EntryWritten, which works fine until someone
clears the log. After clearing the log it won't receice events any longer. Is
this a bug or feature? If a feature how to...
|
by: Polar |
last post by:
Hello everyone! I'm new here.
I am doing a project, Digital Compass Navigation Aids. It consists of the 1490 Digital Compass, a P18F4620 Microcontroller, ISD2560 voice record/playback chip LM4808M...
|
by: Martin |
last post by:
Is clearing a structure the following way well defined in C89? The
structure ACTION contains no floating point or pointer members. Only
integral types. My thoughts concern the padding - can and...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |