bit convertion problem

T

tsunami

I have written a bitarray class which has a constructor taking bit
stream as a string parameter.but it gives me an error such that cannot
convert 'char*' to 'unsigned char*'.where I have declared bitarray as:

unsigned char *bitarray; and the constructor is:

BitArray::BitArray( const char* inputsize)
{
bitarray=new char[strlen(inputsize)+1];
strcpy(this->bitarray,inputsize);
this->length=strlen(inputsize);
return;
}
 
A

Andrey Tarasevich

tsunami said:
I have written a bitarray class which has a constructor taking bit
stream as a string parameter.but it gives me an error such that cannot
convert 'char*' to 'unsigned char*'.where I have declared bitarray as:

unsigned char *bitarray; and the constructor is:

BitArray::BitArray( const char* inputsize)
{
bitarray=new char[strlen(inputsize)+1];
strcpy(this->bitarray,inputsize);
this->length=strlen(inputsize);
return;
}

'strcpy' expects a 'char*' as its first argument and you are trying to
pass a 'unsigned char*' instead. That's what's causing the error message.

It is hard to suggest a way out of this since your intent is not exactly
clear from the code provided. If you are planning to store an ASCII
representation of your "bit array" in the memory pointed by
'this->bitarray' (which is a rather strange way to implement a bit
array), why don't you just declare 'bitarray' field as a 'char*'?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,348
Latest member
RoscoeNevi

Latest Threads

Top