|
Boost Users : |
From: Daryle Walker (darylew_at_[hidden])
Date: 2008-09-01 15:53:36
On Aug 28, 2008, at 10:47 PM, Diane wrote:
> Based on tutorial and reference material, and some previous posts
> here, it seems
> like I should be able to serialize a char* by using a wrapper like
> tracked_char:
>
> BOOST_STRONG_TYPEDEF(char, tracked_char)
>
> template<class Archive>
> void serialize(Archive &ar, tracked_char & tc){
> ar & tc;
> }
>
> But when I try to serialize my struct that contains char*:
>
> typedef struct MYSTRUCT
> {
> char chtest;
> char *chstar;
> } MYSTRUCT;
>
> template<class Archive>
> void serialize(Archive & ar, MYSTRUCT & it, const unsigned int
> version)
> {
> ar & it.chtest;
> tracked_char *tcp = it.chstar; //****error on this line****//
> ar & *tcp;
> }
>
> I get this compile error: cannot convert `char*' to `tracked_char*' in
> initialization
>
> What is the compiler complaining about here? How do I fix it? I'm
> not sure if I
> have the correct usage of BOOST_STRONG_TYPEDEF, so I also tried:
You (generally?) can't convert one data pointer to another, unless
the receiving type is "void" or an unambiguous base class type, and
has at least as many cv-qualifiers. If a BOOST_STRONG_TYPEDEF is
what it says, then the pointer types have to be incompatible! That's
why the conversion fails. I'm not sure that generated strong-
typedefs are supposed to be compatible beyond the direct level.
> struct tracked_char {
> char m_char; // the real data
> template<class Archive>
> void serialize(Archive &ar, unsigned int version){
> ar & m_char;
> }
> // casting operators - not compiled
> char operator char () const { //****error here****//
> return m_char;
> }
> char & operator char() { //****error here****//
> return m_char;
> }
> };
>
> I need someone to point me in the right direction.
Have you written a conversion operator before? You leave out the
return type; the type given in the name already tells the compiler
what you want.
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net