I started testing the C ++ 11 standard, and I found this question that describes how to call your ctor from another ctor in the same class to avoid using the init method or the like. Now I'm trying to do the same with code that looks like this:
HPP:
class Tokenizer { public: Tokenizer(); Tokenizer(std::stringstream *lines); virtual ~Tokenizer() {}; private: std::stringstream *lines; };
castes:
Tokenizer::Tokenizer() : expected('=') { } Tokenizer::Tokenizer(std::stringstream *lines) : Tokenizer(), lines(lines) { }
But this gives me an error: In constructor 'config::Tokenizer::Tokenizer(std::stringstream*)': /path/Tokenizer.cpp:14:20: error: mem-initializer for 'config::Tokenizer::lines' follows constructor delegation I tried to move the part of Tokenizer () first and last in the list, but that didn't help.
What is the reason for this and how can I fix it? I tried moving lines(lines) to the body using this->lines = lines; and it works great. But I really would like to be able to use a list of initializers.
Thanks in advance!
c ++ gcc c ++ 11 ctor-initializer
lfxgroove Aug 30 2018-12-12T00: 00Z
source share