c++ - Why does this compile without errors? (Returning a type that doesn't subclass the stated returned type) -



c++ - Why does this compile without errors? (Returning a type that doesn't subclass the stated returned type) -

i've inherited std::list allow 'psuedo random access' [] operator.

#include <list> template <typename t> class rlist : public std::list<t> { t& operator[](int index){ typename std::list<t>::iterator iterator; int pos; (iterator = this->begin(), pos = 0; iterator != this->end(); iterator++, pos++) if (pos == index) homecoming *iterator; homecoming inexistent_element(); } class inexistent_element { }; };

inexistent_element not yet inherit t, shouldn't compile. compiles. i'm pretty sure c++ shouldn't allow me pass non-const reference object created inline.

i'm using code::blocks ide mingw gcc compiler. i'd know why compiles.

the fellow member function operator[] never instantiated you. how know that? it's private.

note instantiating class not automatically instantiate fellow member functions ([temp.inst]/1):

the implicit instantiation of class template specialization causes implicit instantiation of declarations, not of definitions or default arguments, of class fellow member functions, fellow member classes, scoped fellow member enumerations, static info members , fellow member templates;

c++ inheritance

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -