hello.
I'm testing the "classes" and I tried to insert an array in the following exercise, a variant of the example proposed by the tutorial.
The program is regularly compiled and starts executing, but at some point, it crashes.
Also, if I move the "m.printer ()" outside "while" loop, the program compiles, but when I run it, it gives me an error like: bad_alloc ().
thanks for any suggestions.
bye
p.s.- have not added comments because it is a very simple program.
#include <iostream>
usingnamespace std;
class test
{
private:
int x;
int y;
int size;
int* multi = newint[size];
public:
int counter = 0;
void set_values (int, int);
void multipler (int, int);
void printer ();
};
inlinevoid test::set_values ( int a, int b )
{
x = a;
y = b;
size = counter;
}
inlinevoid test::multipler ( int c, int d)
{
multi[counter] = c * d;
counter++;
}
inlinevoid test::printer ()
{
for ( int j=0; j<counter; j++)
{
cout << " result is: " << multi[j] << " counter : " << counter << endl;
}
}
int main()
{
class test m;
int a, b;
while ( m.counter < 10 )
{
cout << " input a, b " << endl;
cin >> a >> b;
m.set_values (a,b);
cout << " ### " << endl;
m.multipler(a,b);
m.printer();
}
//m.printer();
return 0;
}