By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,118 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,118 IT Pros & Developers. It's quick & easy.

decay bug

P: n/a
class DataBuffer {
enum { bufferSize=0x20000 };
unsigned char buffer_[bufferSize];
public:
unsigned char * const Buffer() const {
return buffer_;
};
};

I get the error "cannot convert unsigned char const * to unsigned char *"
with the Buffer function. Is this a compiler bug?

Fraser.
Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Fraser Ross" <f@ross.co.uk> wrote in message
news:1121625327.27ee15d1534a9e3f9cf69d058cd52891@t eranews
class DataBuffer {
enum { bufferSize=0x20000 };
unsigned char buffer_[bufferSize];
public:
unsigned char * const Buffer() const {
return buffer_;
};
};

I get the error "cannot convert unsigned char const * to unsigned
char *" with the Buffer function. Is this a compiler bug?

Fraser.


Move the const to before the * rather than after the *.
--
John Carson
Jul 23 '05 #2

P: n/a
"John Carson"
"Fraser Ross"> > class DataBuffer {
enum { bufferSize=0x20000 };
unsigned char buffer_[bufferSize];
public:
unsigned char * const Buffer() const {
return buffer_;
};
};

I get the error "cannot convert unsigned char const * to unsigned
char *" with the Buffer function. Is this a compiler bug?

Fraser.


Move the const to before the * rather than after the *.
--
John Carson

That can't be the return type because data should be modifyable. The
functions constness affects the error. It compiles when I remove it. I
have const and non-const Buffer functions now.

Fraser.
Jul 23 '05 #3

P: n/a
Fraser Ross wrote:
class DataBuffer {
enum { bufferSize=0x20000 };
unsigned char buffer_[bufferSize];
public:
unsigned char * const Buffer() const {
return buffer_;
};
};

I get the error "cannot convert unsigned char const * to unsigned
char *" with the Buffer function. Is this a compiler bug?


No. Your 'buffer_' is an array of char. In a constant object
(*this in a member declared 'const') that's an array of const char.
You cannot return a pointer to a non-const char from a member that
is declared const.

V
Jul 23 '05 #4

P: n/a
Fraser Ross wrote:
"John Carson"
"Fraser Ross"> > class DataBuffer {
enum { bufferSize=0x20000 };
unsigned char buffer_[bufferSize];
public:
unsigned char * const Buffer() const {
return buffer_;
};
};

I get the error "cannot convert unsigned char const * to unsigned
char *" with the Buffer function. Is this a compiler bug?

Fraser.
Move the const to before the * rather than after the *.
--
John Carson

That can't be the return type because data should be modifyable.


You can't expect to declare your 'DataBuffer' const and at the same
time allow modifications to it.
The
functions constness affects the error. It compiles when I remove it.
Of course. You're only allowed to modify the 'buffer_' (through the
pointer which you return) if the object itself is non-const.
I have const and non-const Buffer functions now.


Good.

V
Jul 23 '05 #5

P: n/a
"Fraser Ross" <f@ross.co.uk> wrote in message
news:1121626339.b8eed5c518467f0ef98217690fec72b6@t eranews
"John Carson"
"Fraser Ross"> > class DataBuffer {
enum { bufferSize=0x20000 };
unsigned char buffer_[bufferSize];
public:
unsigned char * const Buffer() const {
return buffer_;
};
};

I get the error "cannot convert unsigned char const * to unsigned
char *" with the Buffer function. Is this a compiler bug?

Fraser.


Move the const to before the * rather than after the *.
--
John Carson

That can't be the return type because data should be modifyable. The
functions constness affects the error. It compiles when I remove it.
I have const and non-const Buffer functions now.


I don't follow your reasoning. When the function is const, the data is not
modifiable (that is what a const function means) and so the return type must
be a pointer to const char.

If the function is not const, then you can drop const from the return type
entirely.
--
John Carson

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.