0

I am just playing around with std::array. Want to pass an array of integers to a function which can easily be done using

void arrayByValue(array<int, 5> arr);  

The above can be invoked like

array<int, 5> aInt = {100,92,-1,122,112};  
arrayByValue(aInt);  

This works perfectly fine as long as it is in same .cpp file. I am The issue is how to put this in a .h file, implement the method in .cpp file and then invoke it in another file assume main. I receive the error saying
'array': undeclared identifier
type 'int' expected

Please suggest what could be wrong. Please note this works perfect if I declare the function in the same file from where I am invoking it

Sameer Ahuja
  • 71
  • 1
  • 7

2 Answers2

1

You need to add at the top of you .h file:

#include <array>

also use std::array - using namespace std; is a bad habit

marcinj
  • 48,511
  • 9
  • 79
  • 100
1

Apologies for the inconvenience. I forgot to use
using namespace std;
in the .h file. Using the above line or using std::array
resolved the issue

Sameer Ahuja
  • 71
  • 1
  • 7