[Click] strange string

Szymon Jakubczak s.jakubczak at gmail.com
Tue Apr 4 19:40:23 EDT 2006


Hi Koen,

> _dump->add_detailed_info("Hello with xid=" + _info->get_network_id() + " and
> seqnr=" + _info->get_broadcast_seqnr() + " and size=" +
> _info->get_network_size());
>
> Compiling this gives:
> elements/pdhcp/pdhcp_hello_generator.cc:105: error: invalid operands of
>    types `const char*' and `const char[12]' to binary `operator+'

This is just how C++ works. In your call, the first operand is const
char[] and it cannot be implicitly cast to a String (how would the
compiler know this?). Try telling the compiler to do the cast:

add_detailed_info(String("Hello with xid=") + _info->get_network_id()  //...

I didn't compile this, but it should work.

On 4/4/06, Koen Segers <koen.segers at edpnet.be> wrote:
> Hi,
>
> I just found something strange.
> I've created a function called add_detailed_info that has a String parameter.
> When I call this function in the following manner, it doesn't compile.
>
///
>
>
> When I change it to the following, all works wonderful.
> String str = "Hello with xid=";
>                 str += _info->get_network_id();
>                 str += " and seqnr=";
>                 str += _info->get_broadcast_seqnr();
>                 str += " and size=";
>                 str += _info->get_network_size();
>                 _dump->add_detailed_info(str);
>
>
> Now the question is, how is this possible?
> I saw that the string class has overloaded the operator+ for many cases. Is
> there a case missing for what I'm trying to do? Or maybe the operator()?
>
> xid is a uint32_t
> broadcast_seqnr = int
> network_size = int
>
> greetz
> --
>
> Koen Segers



More information about the click mailing list