Optional semicolon in C++ -
the following code compiled fine (without semicolon after each line). why semicolons not needed @ end of each lines under public section?
note: putting semicolon after each lines fine also, seems using semicolon here optional.
template<typename t> class accessor { public: explicit accessor(const t& data) : value(data) {} accessor& operator=(const t& data) { value = data; return *this; } accessor& operator=(const accessor& other) { this->value = other.value; return *this; } operator t() const { return value; } operator t&() { return value; } private: accessor(const accessor&); t value; };
you don't need semicolons after method definition.
the reason semicolon needed after class definition can declare instances of class right after definition:
class x { } x; //x object of type x
for method, argument doesn't hold, semicolon redundant (although legal).
Comments
Post a Comment