Reputation: 391
I have this function:
array<int, 2> foo() { array<int, 2> = nums; return nums;}
This returns the error "array does not name a type". Why is this?
Upvotes: 1
Views: 96
Reputation: 958
You need to include array. And as was pointed out, you have the incorrect syntax for the array declaration.
Try this:
#include <array>
std::array<int, 2> foo() {
std::array<int, 2> nums;
return nums;
}
int main() {
// use your function here
}
Upvotes: 1
Reputation: 62636
The template is spelled std::array
, not array
, and requires you to #include <array>
somewhere preceding that line
#include <array>
std::array<int, 2> foo() { return { 42, 42 }; }
Upvotes: 7