Re: std::transform problem
tech wrote:
Hi, I am trying to use the std::transform as follows
where buf is short*
m_SendData is std::vector<unsigned char>
class CCodec
{
public:
CCodec() {};
virtual ~CCodec(){};
virtual unsigned char Encode(short ibuf ) = 0;
virtual short Decode(unsigned char ibuf) = 0;
};
m_Codec is *CCodec but pointing at concrete implementation
std::transform(buf, buf + LEN, std::back_inserter(m_SendData),
m_Codec-
Encode);
Instead of the expression 'm_Codec->Encode' you probably meant to
use a binder:
'bind1st(mem_fun(&CCodec::Encode), m_Codec)'
(or something like that). The idea is that the last argument to
'transform' needs to be a functor or a function pointer. To make
a functor from an object and a pointer to member, you need to bind
the two together so they can be called like a regular function.
Google "bind1st mem_fun" in the news archives, you'll find more
information.
I get the following errors from VC++ (Visual Studio 8). How to
correct? Thanks
error C3867: CCodec::Encode': function call missing argument list;
use &CCodec::Encode' to create a pointer to member
.: error C2780: '_OutIt
std::transform(_InIt1,_InIt1,_InIt2,_OutIt,_Fn2)' : expects 5
arguments - 4 provided
C:\Program Files\Microsoft Visual Studio 8\VC\ce\include
\algorithm(797) : see declaration of 'std::transform'
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask