I have a simple code sample of a class that wraps boost::tokenizer.
MyTokenizer.h
#pragma once
#include <iostream>
#include <boost/tokenizer.hpp>
class MyTokenizer
{
public:
typedef boost::tokenizer< boost::escaped_list_separator<char> > TokType;
MyTokenizer(std::string);
~MyTokenizer() {};
void printTok();
private:
const TokType tok_;
};
MyTokenizer.cpp
#include "MyTokenizer.h"
MyTokenizer::MyTokenizer(std::string input) :
tok_(input)
{
std::cout << "Created tokenizer from: " << input << std::endl;
for (TokType::iterator it = tok_.begin(); it != tok_.end(); ++it){
std::cout << *it << std::endl;
}
}
void MyTokenizer::printTok(){
std::cout << "printing tokens" << std::endl;
for (TokType::iterator it = tok_.begin(); it != tok_.end(); ++it){
std::cout << *it << std::endl;
}
}
main.cpp
#include "MyTokenizer.h"
int main(void){
std::string input("a,b,c");
MyTokenizer tok(input);
tok.printTok();
}
When I run this example it makes it through the constructor fine, printing the expected tokens in the loop but on the call to printTok() it gives this error
It seems like I cant create an iterator of MyTokenizer outside of the constructor.
Edit
I changed the printTok() method to be even simpler while still throwing the same error it now looks like this.
void MyTokenizer::printTok(){
TokType::iterator it = tok_.begin();
}