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

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -