From 5979939788e171eab224ad2074adc4c6bc3c2cf3 Mon Sep 17 00:00:00 2001 From: Thunder422 Date: Sat, 29 Dec 2012 08:28:56 -0500 Subject: [PATCH] added explicit to constructors to prevent implicit type conversions 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)" --- commandline.h | 2 +- parser.h | 2 +- test_ibcp.h | 2 +- token.h | 2 +- translator.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/commandline.h b/commandline.h index 899b42b..6418366 100644 --- a/commandline.h +++ b/commandline.h @@ -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 diff --git a/parser.h b/parser.h index 67b79e8..fbcfc22 100644 --- a/parser.h +++ b/parser.h @@ -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; diff --git a/test_ibcp.h b/test_ibcp.h index 9ac8c64..93fe6ad 100644 --- a/test_ibcp.h +++ b/test_ibcp.h @@ -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); diff --git a/token.h b/token.h index 97bb3a9..4db5962 100644 --- a/token.h +++ b/token.h @@ -67,7 +67,7 @@ class Token }; public: - Token(int column = -1) + explicit Token(int column = -1) { m_column = column; m_length = 1; diff --git a/translator.h b/translator.h index df3e609..aaa60e6 100644 --- a/translator.h +++ b/translator.h @@ -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) {