#include <iostream.h> class max{ public: void get(int[], int); int sh(int[], int); }; void max::get(int *a, int b) { for (int i=0; i<b; i++) cin>> a; } void max::sh(int *a, int b) { int mx=a[0]; for (int i=1; i,b; i++) if (a>mx) mx=a; return mx; } void main() { max j; int x[3]; j.get(x,3); int m=j.sh(x,3); cout <<"\n MAX= "<<m; } NB: Line number 18 'max::sh(int *,int' cannot return a value Line number 25(a) 'declaration for m' Line number 25(b) 'cannot convert 'void' to 'max' Line number 26 ' Illegal structure operation
member function "sh" is prototyped as returning an int, but the definition is void. fix that and you *should* be okay. why not make your array as a private member of your class? Code: class max { public : max(int init_size = 3) { a = new int[init_size]; asize = init_size; } void get(); int sh() const; ~max() { delete [] a; } ... private : int *a; int asize; }; void max::get() { ... } int max::sh() const { ... } ... when you instantiate an object, the constructor will use the default size of 3 elements or you can specify a size; either case will store the number of elements in the variable asize. Code: max test1, /* default size of 3 */ test2(10); // create 10 elements