access dynamic class members

I'm trying to convert a class array into a dynamically allocated array of class but I can't figure out how to access the class member functions. What syntax would I use to access member functions? Thank you in advance.
. (dot) if you have an object/reference
-> (arrow) if you have a pointer

1
2
3
4
5
6
7
Foo bar;
bar.asdf();
Foo *qwerty = &bar;
qwerty->asdf();

Foo *zxcv = new Foo[42];
zxcv[13].asdf();
theleonicking wrote:
I'm trying to convert a class array into a dynamically allocated array of class but I can't figure out how to access the class member functions. What syntax would I use to access member functions?


arrayName[index].functionName( args )

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 Message
{
   int i;
public:
   Message() {}                        // Needs a constructor with no arguments here
   void set( int inp ) { i = inp; }
   void get() { cout << "Hello " << i << '\n'; }
};


int main()
{
   int N = 5;
   Message *M = new Message[N];
   for ( int i = 0; i < N; i++ ) M[i].set( 10 * i );
   for ( int i = 0; i < N; i++ ) M[i].get();
   delete [] M;
}
"class array" and "array of class" ... do you mean essentially same thing, or something entirely different?
Can you give an example of both so that we know what you talk about?
Topic archived. No new replies allowed.