void validate( char const * first, char const * last) {
for ( ; first ! = last; ++ first) {
if ( * first == 'X' ) throw "How dare you put an 'X' here?" ;
}
}
// Base
struct text {
text( char const * first, char const * last)
: storage( first, last) { } // need to pass first and last to validate() first
std:: string storage;
}
// Option #1
struct validated {
validated( char const * first, char const * last) {
validate( first, last) ;
}
} ;
struct text : validated {
text( char const * first, char const * last)
: validated( first, last) // a bit ugly, if you ask me
storage( first, last) { }
std:: string storage;
}
dm9pZCB2YWxpZGF0ZShjaGFyIGNvbnN0KiBmaXJzdCwgY2hhciBjb25zdCogbGFzdCkgewogICAgZm9yKDsgZmlyc3QgIT0gbGFzdDsgKytmaXJzdCkgewogICAgICAgIGlmKCpmaXJzdCA9PSAnWCcpIHRocm93ICJIb3cgZGFyZSB5b3UgcHV0IGFuICdYJyBoZXJlPyI7CiAgICB9Cn0KCi8vIEJhc2UKc3RydWN0IHRleHQgewogICAgdGV4dChjaGFyIGNvbnN0KiBmaXJzdCwgY2hhciBjb25zdCogbGFzdCkKICAgIDogc3RvcmFnZShmaXJzdCwgbGFzdCkge30gLy8gbmVlZCB0byBwYXNzIGZpcnN0IGFuZCBsYXN0IHRvIHZhbGlkYXRlKCkgZmlyc3QKCiAgICBzdGQ6OnN0cmluZyBzdG9yYWdlOwp9CgovLyBPcHRpb24gIzEKc3RydWN0IHZhbGlkYXRlZCB7CiAgICB2YWxpZGF0ZWQoY2hhciBjb25zdCogZmlyc3QsIGNoYXIgY29uc3QqIGxhc3QpIHsKICAgICAgICB2YWxpZGF0ZShmaXJzdCwgbGFzdCk7CiAgICB9Cn07CgpzdHJ1Y3QgdGV4dCA6IHZhbGlkYXRlZCB7CiAgICB0ZXh0KGNoYXIgY29uc3QqIGZpcnN0LCBjaGFyIGNvbnN0KiBsYXN0KQogICAgOiB2YWxpZGF0ZWQoZmlyc3QsIGxhc3QpIC8vIGEgYml0IHVnbHksIGlmIHlvdSBhc2sgbWUKICAgICAgc3RvcmFnZShmaXJzdCwgbGFzdCkge30KCiAgICBzdGQ6OnN0cmluZyBzdG9yYWdlOwp9Cg==
compilation info
prog.cpp:12: error: ‘string’ in namespace ‘std’ does not name a type
prog.cpp: In constructor ‘text::text(const char*, const char*)’:
prog.cpp:10: error: class ‘text’ does not have any field named ‘storage’
prog.cpp: At global scope:
prog.cpp:20: error: multiple types in one declaration
prog.cpp:22: error: redefinition of ‘struct text’
prog.cpp:8: error: previous definition of ‘struct text’
prog.cpp:28: error: expected unqualified-id at end of input
stdout