Re: constructor problem
From: Vince Morgan (vir_at_optusnet.com.au)
Date: 03/26/05
- Next message: Mike Wahler: "Re: Use of new and delete in C++"
- Previous message: Eric A. Johnson: "How can I call an enclosing class's function?"
- In reply to: Andrey Tarasevich: "Re: constructor problem"
- Next in thread: Vince Morgan: "Re: constructor problem"
- Reply: Vince Morgan: "Re: constructor problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 26 Mar 2005 12:18:08 +1000
"Andrey Tarasevich" <andreytarasevich@hotmail.com> wrote in message
news:11493oes2h5asaa@news.supernews.com...
> tsunami wrote:
> > ...
> > I am trying to write a BitArray class;one of my constructors take
> > string stream such as:
> > BitArray d="1010101010";
> > I want to pass this "101010" into my constructor but it gives a
> > conversion error such as cannot convert to 'char *' to 'unsigned char
> > *' where I have defined my bitarray as:
> > unsigned char* bitarray;
> > I am including the BitArray constructor that I have written:
> >
> > 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*'?
>
> --
> Best regards,
> Andrey Tarasevich
Please excuse my ignorance, but aren't there issues with regard to using
signed types in a bit array?
Vince Morgan
- Next message: Mike Wahler: "Re: Use of new and delete in C++"
- Previous message: Eric A. Johnson: "How can I call an enclosing class's function?"
- In reply to: Andrey Tarasevich: "Re: constructor problem"
- Next in thread: Vince Morgan: "Re: constructor problem"
- Reply: Vince Morgan: "Re: constructor problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|