I'm revising C++ and I got error, but I'm pretty sure this passed in Microsoft Visual Studio, is my syntax really incorrect or is this just Code::Blocks specific issue? Because I wrote for loop just as is in tutorial(version that is commented out works).
int* returnArray(int size)
{
return new int[size];
}
int main()
{
int *myarray = returnArray(10);
for(auto const &index : myarray)
std::cout << index;
// for(int i = 0; i < 10; i++)
// std::cout << myarray << "\n";
delete[] myarray;
return 0;
}
Build log:
-------------- Build: Debug in exercise (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -g -std=c++14 -c /home/uros/Namizje/CodeblocksProjects/exercise/main.cpp -o obj/Debug/main.o
/home/uros/Namizje/CodeblocksProjects/exercise/main.cpp: In function ‘int main()’:
/home/uros/Namizje/CodeblocksProjects/exercise/main.cpp:63:29: error: ‘begin’ was not declared in this scope
for(auto const &index : myarray)
^
/home/uros/Namizje/CodeblocksProjects/exercise/main.cpp:63:29: note: suggested alternative:
In file included from /usr/include/c++/5/string:51:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from /home/uros/Namizje/CodeblocksProjects/exercise/main.cpp:1:
/usr/include/c++/5/bits/range_access.h:105:37: note: ‘std::begin’
template<typename _Tp> const _Tp* begin(const valarray<_Tp>&);
^
/home/uros/Namizje/CodeblocksProjects/exercise/main.cpp:63:29: error: ‘end’ was not declared in this scope
for(auto const &index : myarray)
^
/home/uros/Namizje/CodeblocksProjects/exercise/main.cpp:63:29: note: suggested alternative:
In file included from /usr/include/c++/5/string:51:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/ostream:38,
from /usr/include/c++/5/iostream:39,
from /home/uros/Namizje/CodeblocksProjects/exercise/main.cpp:1:
/usr/include/c++/5/bits/range_access.h:107:37: note: ‘std::end’
template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
^
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))