2

Visual Studio 2019 is saying that there is a syntax error on line 30, it is saying there is an unexpected ']' despite the fact that the only closing bracket is closing an opening bracket. I don't know why this is occurring, this has never happened to me, I genuinely do not know what to do.

template <class T>
void DefinedLog(T out) {
    try {
        std::cout << G_RGB() << out << "\33[0m" << std::endl;
    } catch (int) {
        DE_UNUSABLE_PARAM_EXCEPTION e;
        Debug debug;
        debug.SetColor(new int[] {255, 0, 0}); // line 30
        debug.DefinedLog(e.what();)
    }
}
Zeeen
  • 312
  • 1
  • 2
  • 13
  • 1
    An "unexpected" token means that some *other* token should have been in that space instead. It doesn't *necessarily* mean that the token specified as "unexpected" isn't allowed at all. It can mean that something else has to come first. – Karl Knechtel Oct 27 '20 at 16:41
  • 2
    Why was this question closed as being a duplicate question. This is NOT a duplicate QUESTION, but is a duplicate ANSWER (which are NOT the same thing). Does a duplicate answer (3) imply that the question "How many sides are in a triangle" the same question as "what is the square root of 9"? How are the QUESTIONs the same??? – franji1 Oct 27 '20 at 16:55
  • Yeah I don't understand why it was closed, Stack Overflow should definitely have an option to appeal closed questions. – Zeeen Oct 27 '20 at 20:36

2 Answers2

5

C++ isn't that clever yet.

You need new int[3] {255, 0, 0}; which will create an array of 3 ints with the values 255, 0, and 0.

I believe this will be fixed in later standards.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
  • 3
    I'm pretty sure [we're there already](https://wandbox.org/permlink/KvQWTldXaGMvykZs), unless Clang is slipping an extension past `-pedantic-errors`... – Quentin Oct 27 '20 at 16:41
  • @Bathsheba I'm compiling with C++14 there :/ – Quentin Oct 27 '20 at 16:42
  • @Quentin At least with the current draft standard according to [this](https://timsong-cpp.github.io/cppwp/expr.new#6) and the [grammar it refers to](https://timsong-cpp.github.io/cppwp/expr.new#nt:noptr-new-declarator) it's not legal. – NathanOliver Oct 27 '20 at 16:45
  • Welps, looks like both Clang and GCC give this a pass. TIL. – Quentin Oct 27 '20 at 16:47
  • And MSVC 2019 also accepts without the size, in C++14 or C++17 standard. – prapin Oct 27 '20 at 19:57
2

You need to explicitly give the size of the SetColor array param --> new int[size].

cabrillosa
  • 155
  • 8