c++ - How access member function from arrayobject in a loop -


i trying access public function get_data(), generate output "here ", see if creating dynamic object array of object..so how can that.

#include<iostream> #include <conio.h>  using namespace std; int counts = 0; int no_of_array;  class matrix {     int **dynamicarray;  public:      matrix()     {         counts++;         dynamicarray = new int *[3];          (int = 0; < 3; i++)         {             dynamicarray[i] = new int[3];         }     }      void get_data(){          cout << "here \n";     } };  int main() {     int newvalue = 1;     int i;     matrix *array_object[100];     int choice;     while (newvalue == 1){         cout << "enter choice \n 1. 2 matrix addition \n 2. 2 matrix multiplication \n";         cin >> choice;         if (choice == 1)         {             cout << "how many array add \n";             cin >> no_of_array;             (i = 0; <= no_of_array; i++)             {                 array_object[i] = new matrix();             }              (i = 0; < no_of_array; i++)             {                 array_object[i].get_data();              }         }         else if (choice == 2)         {             matrix mul;             //  mul.multiplication();                 }         else             cout << "do enter correct choice \n";          cout << "press 1 enter again , 0 exit \n";         cin >> newvalue;     }     getch();     return 0; } 

i trying check here, if objects created, get_data function called or not... instead error get_data has not been decleared.

use array_object[i]->get_data(); instead of array_object[i].get_data();.

the dot(.) operator used when object try access class member functions/variables whereas arrow(->) operator used if object pointer.

now, declared

matrix *array_object[100];  

which means array_object array of matrix pointers. hence need use arrow(->) instead of dot(.) operator.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -