Originally Posted by
jwenting
Personally I hate every compiler error, they indicate a flaw in my knowledge of the language constructs I try to use which means my understanding of the language itself is incomplete.
While they can be helpful to point out things like honest typos, those too I should have caught.
Sorry, that is complete bull......... A good C++ programmer will design his classes in such a way that even a syntactically correct but incorrect use will generate a compile-time error.
for example, to borrow from Scott Meyers (effective C++ 3rd ed item 18) you could design a Date class like this
Code:
class Date
{
int day, month;
public:
Date(int d, int m);
};
but then an american comes along and goes
Code:
// hmm need a date for christmas
Date xmasDay(12, 25); // oh crap
whereas you can instead use something like
Code:
class Date
{
public:
enum Month
{
jan, feb,mar // etc
};
Date(int d, Month m);
private:
int day;
Month month;
};
// hmm need a date for christmas
// Date xmasDay(12, 25); // hmm compiler error
Date xmasDay(25, Date::dec); // fixed before runtime!! woohoo
obviously this is a trivial example (and that is bordeline pseudo-code, so don't bother criticizing the style), but it illustrates the concept of using the compiler to enforce design constraints