Re: wat is wrong in my code
On 16 Apr., 10:52, Pradeep <bubunia2000s...@gmail.com> wrote:
Hi all,
Hello, Pradeep. Are you related to smilesonisamal@gmail ?
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/3a4a17f01=
cff3068/
I want to copy intermediate elements from a vector to another.
The problem is I am getting same value in m_Data[6] ...[11]for
all elements. (&srcPtr[0] value- for exp 205).
Am I missing anything?
std::vector<uint_8*> (m_Data);
What kind of syntax is that?
Why don't you write
std::vector<uint_8*> m_Data;
instead? Note: You're creating an EMPTY vector.
uint8_t *srcPtr = new uint8_t[6];
memset(static_cast<uint8_t*>(srcPtr), 0,(sizeof (uint8_t)* 6));
Why the static_cast? It's useless here.
if(srcPtr)
{
srcPtr= // A API returning const_uint*
}
The expression "new uint8_t[6]" -- provided uint8_t is a type --
returns a non-zero pointer or throws an exception. So the boolean
expression in the if-statement will always be false. Assuming
"const_uint" is equivalent to "const uint8_t" you can't convert these
pointer types without a const_cast.
m_Data[6] = &srcPtr[0];
m_Data[7] = &srcPtr[1];
m_Data[8] = &srcPtr[2];
m_Data[9] = &srcPtr[3];
m_Data[10]= &srcPtr[4];
m_Data[11]= &srcPtr[5];
For this to work safely you need m_Data.size()>=12. But your vector
is empty!
Check the FAQ on how to post questions, how to post code, etc etc ...
Cheers!
SG