The following code compiled fine (without semicolon after each line). Why are semicolons not needed at the end of each lines under the public section?
Note: putting a semicolon after each lines is fine also, so it seems like using semicolon here is 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 a method definition.
The reason a semicolon is needed after a class definition is that you can declare instances of the class right after the definition:
class X
{
} x;
//x is an object of type X
For method, this argument obviously doesn't hold, so a semicolon would be redundant (although legal).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With