I'm trying to compile a simple shared pointer declaration but using g++ -std=c++11 main.cpp -o main
using cmd but due to some reasons it throws a bunch of errors. I tried finding similar questions on Stack Overflow but none of them matches my problem.
code:
std::shared_ptr<int[]>array(new int[100]);
Header files:
#include<iostream>
#include<memory>
compiler version: g++ (MinGW.org GCC-6.3.0-1) 6.3.0
Error:
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\shared_ptr.h:52:0,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\memory:82,
from main.cpp:2:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\shared_ptr_base.h: In instantiation of 'std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Tp1*) [with _Tp1 = int; _Tp = int []; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]':
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\shared_ptr.h:117:32: required from 'std::shared_ptr<_Tp>::shared_ptr(_Tp1*) [with _Tp1 = int; _Tp = int []]'
main.cpp:7:42: required from here
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\shared_ptr_base.h:885:39: error: cannot convert 'int*' to 'int (*)[]' in initialization
: _M_ptr(__p), _M_refcount(__p)
^`
I'm relatively new and don't know what this error means. Any suggestions would be helpful.