0

mac os, visual studio code has errors.
I have two errors in vs code, but my code is compiling in onlinegdb.

onlinegdb: https://onlinegdb.com/jec457D_K

#include <iostream>
#include <initializer_list>

template <typename T = float>
class Matrix
{
public:
    int m_rows;
    int m_columns;
    T* m_ptr;
    Matrix(std::initializer_list<T> list)
    {
        m_rows = list.size();
        m_ptr = new T[m_rows];
        int i = 0;
        for(auto elements : list){
            std::cout << "This is elem " << elements << std::endl;
            *(m_ptr + i) =  elements;
            i++;
        }
    }
    ~Matrix() { delete[] m_ptr; }
};


int main()
{
    Matrix<int> m({1, 2 ,4});

    return 0;
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64
KoIIuJIkA
  • 1
  • 1
  • 2
    Try compiling for the C++11 standard or newer. – molbdnilo Dec 05 '22 at 15:16
  • 2
    The inbuilt compiler on mac defaults to C++98 mode – NathanOliver Dec 05 '22 at 15:16
  • The official VSCode macOS documentation tells you how to fix this here: [https://code.visualstudio.com/docs/cpp/config-clang-mac](https://code.visualstudio.com/docs/cpp/config-clang-mac) see the 2 places in the json files where c++17 is specified. – drescherjm Dec 05 '22 at 15:24

0 Answers0