Hi,
compiling this program with g++ 4.7.1 ...
#include
On 07/08/2014 09:40 p.m., Jono Poff wrote:
Hi,
compiling this program with g++ 4.7.1 ...
#include
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