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: 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. Thanks, Diane
On 28 Aug 2008, at 20:47, Diane wrote:
tracked_char *tcp = it.chstar; //****error on this line****// ar & *tcp; }
I get this compile error: cannot convert `char*' to `tracked_char*' in initialization
Can you try tracked_char* tcp(it.chstar) That sometimes works for me if I have such problems Matthias
Are you sure really want to do this? look into binary object. Robert Ramey Matthias Troyer wrote:
On 28 Aug 2008, at 20:47, Diane wrote:
tracked_char *tcp = it.chstar; //****error on this line****// ar & *tcp; }
I get this compile error: cannot convert `char*' to `tracked_char*' in initialization
Can you try
tracked_char* tcp(it.chstar)
That sometimes works for me if I have such problems
Matthias
How would you serialize pointers as binary objects? On 29 Aug 2008, at 17:13, Robert Ramey wrote:
Are you sure really want to do this? look into binary object.
Robert Ramey
Matthias Troyer wrote:
On 28 Aug 2008, at 20:47, Diane wrote:
tracked_char *tcp = it.chstar; //****error on this line****// ar & *tcp; }
I get this compile error: cannot convert `char*' to `tracked_char*' in initialization
Can you try
tracked_char* tcp(it.chstar)
That sometimes works for me if I have such problems
Matthias
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I'm suspecting that there is a confusion about how to seriailzation a pointer to a null terminated string. It's natural to want to do something like char *p; ... p = "jsdkfjads" ... ar & p; because the library syntax encourages one to think that way. But in this case, one would want save(... int i = strlen(p); ar << i; ar << binary_object(i, p); } load(... int i; ar >> i; ar >> binary_object(i,p); } That is, I think the question reflects a mis-conception about the best way to use the library. Robert Ramey Matthias Troyer wrote:
How would you serialize pointers as binary objects?
On 29 Aug 2008, at 17:13, Robert Ramey wrote:
Are you sure really want to do this? look into binary object.
Robert Ramey
Matthias Troyer wrote:
On 28 Aug 2008, at 20:47, Diane wrote:
tracked_char *tcp = it.chstar; //****error on this line****// ar & *tcp; }
I get this compile error: cannot convert `char*' to `tracked_char*' in initialization
Can you try
tracked_char* tcp(it.chstar)
That sometimes works for me if I have such problems
Matthias
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
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
participants (4)
-
Daryle Walker
-
Diane
-
Matthias Troyer
-
Robert Ramey