J
JKop
Back when I read my first C++ book, I was given the following scenario:
class Cheese
{
public:
int number_of_holes;
int colour;
};
The thing is, you want the "user" of this class to be able to read from the
two above variables, but no be able to change them. The book retardly gave
the following:
class Cheese
{
private:
int number_of_holes;
int colour;
public:
int GetNumberOfHoles(void);
int GetColour(void);
};
What do yous think of the following:
class Cheese
{
private:
int number_of_holes;
int colour;
public:
const int& GetNumberOfHoles(void)
{
return number_of_holes;
}
const int& GetColour(void)
{
return colour;
}
};
int main(void)
{
Cheese chalk;
chalk.GetNumberOfHoles();
}
I wonder was so many books think they have to show you the stupid way before
they give you the lean, mean, efficient way.
-JKop
class Cheese
{
public:
int number_of_holes;
int colour;
};
The thing is, you want the "user" of this class to be able to read from the
two above variables, but no be able to change them. The book retardly gave
the following:
class Cheese
{
private:
int number_of_holes;
int colour;
public:
int GetNumberOfHoles(void);
int GetColour(void);
};
What do yous think of the following:
class Cheese
{
private:
int number_of_holes;
int colour;
public:
const int& GetNumberOfHoles(void)
{
return number_of_holes;
}
const int& GetColour(void)
{
return colour;
}
};
int main(void)
{
Cheese chalk;
chalk.GetNumberOfHoles();
}
I wonder was so many books think they have to show you the stupid way before
they give you the lean, mean, efficient way.
-JKop