M Powell <
foru...@gmail.com> writes:
> Hi all, thought I had a decent handle on some aspects of C++ but this
> one has me stomped.
You've hit a bug in Google Groups that drops the ++ from the group name
so you've posted in comp.lang.c. I've replied, including comp.lang.c++
in the newsgroups and I've set a followup-to header. This may fix
things up.
> I'm using an API (Driver that I cant change).
One problem is in the class Driver. If you can't change that, you're
stuck.
> For brevity here's a snippet
>
> #include <iostream>
> #include <sstream>
> #include <string>
>
>
> template < class In, unsigned int In_depth ,
> class Out, unsigned int Out_depth >
> class Driver {
> public :
> bool GetFromOutputFIFO ( Out& msg_data, unsigned int & msg_size ) {
> //stuff
> return true ;
> }
>
> bool GetFromOutputFIFO ( const void* msg_data, unsigned int & msg_size ) {
> return GetFromOutputFIFO ( * (const In *) msg_data, msg_size ) ;
> }
Something is wrong here. These two overloads are inconsistent. In the
first, msg_data is not const and it is in the second.
It's not at all clear how this should be fixed. Ideally, you want
everything to be either const or not const.
The minimal change is to make the first msg_data a const Out &, but that
might be entirely wrong. The name of the function suggests it modifies
msg_data in which case it should not be const. That means the problem
is in the second overload and in the code below where things are
declared const that should not be.
> };
>
> class Foo
> {
> Driver < unsigned char, 10, unsigned char, 10 > driver ;
> public :
> unsigned int WriteOut ( const unsigned int address, const unsigned char* buf,
> const unsigned int len, const bool send )
> {
> unsigned int ll = len ;
> driver.GetFromOutputFIFO ( buf , ll );
> //driver.GetFromOutputFIFO ( const_cast < unsigned char* > ( buf ), ll );
> //driver.GetFromOutputFIFO
> //( const_cast < unsigned char* > ( const_cast < unsigned char* > ( buf ) ), ll );
>
> }
> };
>
> int main()
> {
> }
>
>
> The error
> error: binding reference of type ‘unsigned char&’ to ‘const unsigned char’ discards qualifiers
>
> How do I pass in buf to GetFromOutputFIFO ?
Start by saying exactly what the API is. That was we know what the
target functions look like.
--
Ben.