|
Boost Users : |
Subject: Re: [Boost-users] Boost::Tokenizer / "string iterators incompatible" error on Visual C++ 2010 Express - runs ok on gcc4.6.0
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2011-08-01 14:26:55
Hi Asif,
On Mon, Aug 1, 2011 at 10:45 AM, asif saeed <asif.lse2_at_[hidden]> wrote:
> Base(std::string s) : sep_(";"),
> tok_(s,sep_),
> i_(tok_.begin())
> {
> }
These lines are your problem -- the tokenizer stores the iterators
from the string 's', but once the constructor is exited (prior to the
body of the derived class being called) the argument 's' is destroyed
-- invalidating the iterators stored by the tokenizer data member.
Try the following change to Base:
class Base
{
public:
typedef boost::char_separator<char> sep_type_t;
typedef boost::tokenizer<sep_type_t> tokenizer_t;
Base(std::string s)
: s_(s),
sep_(";"),
tok_(s_,sep_),
i_(tok_.begin())
{}
std::string nextToken()
{
if (i_!=tok_.end())
return *i_++;
else
return "";
}
protected:
std::string s_;
sep_type_t sep_;
tokenizer_t tok_;
tokenizer_t::iterator i_;
};
HTH,
Nate
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