Hi, compiling this program with g++ 4.7.1 ... #include <boost/serialization/strong_typedef.hpp> BOOST_STRONG_TYPEDEF(uint32_t, LINKID_T) int main() { LINKID_T lid = 0xffddee33; return 0; } I get error: conversion from 'unsigned int' to non-scalar type 'LINKID_T' requested Looking at the header, the strong typedef struct defines assignment from uint32_t to LINKID_T ... D & operator=(const T & rhs) { t = rhs; return *this;} ... so what gives? Cheers, Jono -- ------------------------------ This email, including any attachments, is only for the intended recipient. It is subject to copyright, is confidential and may be the subject of legal or other privilege, none of which is waived or lost by reason of this transmission. If you are not an intended recipient, you may not use, disseminate, distribute or reproduce such email, any attachments, or any part thereof. If you have received a message in error, please notify the sender immediately and erase all copies of the message and any attachments. Unfortunately, we cannot warrant that the email has not been altered or corrupted during transmission nor can we guarantee that any email or any attachments are free from computer viruses or other conditions which may damage or interfere with recipient data, hardware or software. The recipient relies upon its own procedures and assumes all risk of use and of opening any attachments. ------------------------------
On 07/08/2014 09:40 p.m., Jono Poff wrote:
Hi,
compiling this program with g++ 4.7.1 ...
#include <boost/serialization/strong_typedef.hpp> BOOST_STRONG_TYPEDEF(uint32_t, LINKID_T)
int main() { LINKID_T lid = 0xffddee33; return 0; }
I get
error: conversion from 'unsigned int' to non-scalar type 'LINKID_T' requested
Looking at the header, the strong typedef struct defines assignment from uint32_t to LINKID_T ...
D & operator=(const T & rhs) { t = rhs; return *this;}
... so what gives?
The expression `LINKID_T lid = 0xffddee33;` would be doing construction, not assignment. The constructor that would be picked would be the conversion construction `explicit D(const T t_) : t(t_) {};` followed by the copy construction `D(const D & t_) : t(t_.t){}`, but the conversion constructor is not viable because it is `explicit`. What you can do is either: LINKID_T lid = LINKID_T(0xffddee33); or simply: LINKID_T lid(0xffddee33); Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
participants (2)
-
Agustín K-ballo Bergé
-
Jono Poff