syntax error: ']' was unexpected here, despite the fact that there is no extra ']' anywhere?

Viewed 141

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();)
    }
}
2 Answers

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.

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

Related