Last active
August 12, 2017 21:11
-
-
Save JayBazuzi/b657f62d7bcb4633871d313bb7d25758 to your computer and use it in GitHub Desktop.
C++ value type styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Size | |
{ | |
int m_width; | |
int m_height; | |
public: | |
Size(int width, int height) | |
: m_width(width) | |
, m_height(height) | |
{} | |
int GetWidth() const { return m_width; } | |
int GetHeight() const { return m_height; } | |
void SetWidth(int width) { m_width = width; } | |
void SetHeight(int height) { return m_height = height; } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Size | |
{ | |
int width; | |
int height; | |
public: | |
Size(int width, int height) | |
: width(width) | |
, height(height) | |
{} | |
int Width() const { return this->width; } | |
int Height() const { return this->height; } | |
void SetWidth(int width) { this->width = width;} | |
void SetHeight(int height) { this->height = height;} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Size | |
{ | |
int width; | |
int height; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The struct.
I am not a fan of empty properties. Anders and I talked about this in the early days of C#, and he was of the same opinion, so I started to suggest that to people that maybe that made more sense than writing properties.
And then I stopped doing it because people kept looking at me as if I had grown an extra arm.
It wasn't helped by all the BCL features that supported properties but not fields.
My only exception is if I am shipping a library and I'm going to need binary compatibility when I version it, but I don't think that applies to to value types.