how to initialize arrays in constructor using passing by value

Hello all, i want to initialize an array in constructor and return it to main.
I wrote a code but could not resolve.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

class ArrTest{
    int num[25];
public:
    ArrTest(int i){
        for(int j=0; j < 25; j++){
            num[j] = i+1;
        }
    }
        
    int *PrintValues() { return num; }
};

int main(){
    ArrTest obj(10);
    cout<<obj.PrintValues;
    return 0;
}


Anybody can help me?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
using namespace std;

class ArrTest {
    int num[25];
public:
	
    ArrTest(int i)
	{
        for(int j=0; j < 25; j++){
            num[j] = i+j;
        }
    }
        
    int* PrintValues() { return num; }
};

void print (int ar[], int size){
	
	for(int i=0; i<size; i++)
	{
		cout << ar[i] << " ";
	}
	return;
}

int main(){
	
	ArrTest obj(10); 
  
	print( obj.PrintValues() , 25);     
  
	return 0;
}
Topic archived. No new replies allowed.