Skip to content

Commit

Permalink
added explicit to constructors to prevent implicit type conversions
Browse files Browse the repository at this point in the history
for example, this will prevent "Token token = 47" because this is an
undesired implicit conversion from an integer, which would have been
allowed without the 'explicit' keyword on the constructor definition
for "Token(int column = -1)"
  • Loading branch information
thunder422 committed Dec 29, 2012
1 parent 54a5b24 commit 5979939
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion commandline.h
Expand Up @@ -45,7 +45,7 @@ class CommandLine
QTextStream m_cout;
QString m_usage;
public:
CommandLine(const QStringList &args);
explicit CommandLine(const QStringList &args);
~CommandLine();

bool processed(void) const // if processed then exit program
Expand Down
2 changes: 1 addition & 1 deletion parser.h
Expand Up @@ -54,7 +54,7 @@ class Parser
void skipWhitespace();
int scanWord(int pos, DataType &datatype, bool &paren);
public:
Parser(Table &table): m_table(table) {}
explicit Parser(Table &table): m_table(table) {}
void setInput(const QString &input)
{
m_input = input;
Expand Down
2 changes: 1 addition & 1 deletion test_ibcp.h
Expand Up @@ -64,7 +64,7 @@ class Tester
QString m_testFileName; // name of test file (OptFile only)
QString m_errorMessage; // message if error occurred
public:
Tester(const QStringList &args);
explicit Tester(const QStringList &args);
~Tester(void) {}

static QStringList options(void);
Expand Down
2 changes: 1 addition & 1 deletion token.h
Expand Up @@ -67,7 +67,7 @@ class Token
};

public:
Token(int column = -1)
explicit Token(int column = -1)
{
m_column = column;
m_length = 1;
Expand Down
2 changes: 1 addition & 1 deletion translator.h
Expand Up @@ -176,7 +176,7 @@ class Translator
QString m_errorMessage; // message of error that occurred

public:
Translator(Table &table): m_table(table), m_output(NULL),
explicit Translator(Table &table): m_table(table), m_output(NULL),
m_pendingParen(NULL), m_errorToken(NULL) {}
~Translator(void)
{
Expand Down

0 comments on commit 5979939

Please sign in to comment.