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.
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?
#include <iostream>
usingnamespace 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?