// array5.cpp - friend function
// This program will compile, but it won't link without the set() definition
#include <iostream>
usingnamespace std;
#define SIZE 10
class intArray {
private:
int a[SIZE];
public:
void setVal(int index, int value);
friendvoid print(intArray);
};
void print(intArray x) {
int i;
for(i = 0; i < SIZE; i++)
cout << "a[" << i << "] = " << x.a[i] << endl;
}
int main() {
intArray num;
int i;
for(i = 0; i < SIZE; i++)
num.setVal(i,i);
print(num);
return 0;
}
You didn't specify what the setVal function does. You should do that in a file named intArray.cpp
Also, avoid using #define like you do on line 8, make it a const variable inside main instead. And pass it to what ever function needs it. So that means making a constructor for your class.