Class:

class Snumbers{ double metod(double m[]) { /* ---code--- */ return m[0]; // для примера } }; 

The main program:

 int main(){ Snumbers A; int num; cin >> num; double *m1 = new double[num]; for(int i = 0; i < num; i++){ cin >> m1[i]; } cout << A.metod(m1); } 

The question is how can I pass an array to that class method, so that later I would work with it there, and that method would return what I write?

Update

Forgot to add public in class before method. That's how it should be

  class Snumbers{ public: double metod(double m[]) { /* ---code--- */ return m[0]; // для примера } }; 

I get the error:

[bcc32 Error] F1.cpp (27): E2247 'Snumbers :: metod (double *)' is not accessible

  • And what's wrong with the code you provided? - VladD
  • So you forgot it public . - VladD
  • @SkiesX SO is not a forum, when you do not need to answer leading questions in comments, you need to add a question, therefore you should add an error text to the question. Clear? - Cerbo
  • @Cerbo I apologize :) The first time is here. I won in the answers added. Will it be normal? - SkiesX
  • @SkiesX Please use the ability to edit the original message, instead of posting question additions in the form of answers to it. - Nicolas Chabanovsky

1 answer 1

You should also transfer the size of the array to a class method, otherwise how can you work with it if you don't know its size?

 double metod( double * arr, size_t size ) { ... } ... cout << A.metod( m1, num ); 
  • I already know the size of the array in the method. - SkiesX
  • one
    You can know the size if it is a constant, or through some other global / class variable. In another way. - Anton Sazonov