I'm trying to create a pointer to a pointer of a class. I'm trying not to call the default c'tor because he advance the static integer. so I'm using the copy c'tor to avoid advancing the var, the only problem is that I'm not sure what is the correct syntax. here is the code:
#include <stdio.h>
class A
{
static int x;
int m_x;
int m_age;
public:
A(){m_x=x;x++;m_age=0;}
A(const A& that ){m_age =that.m_age; m_x = that.m_x;}
A(int age){m_age = age;}
int getX(){return m_x;}
int getStaticX(){return x;}
int getAge(){return m_age;}
};
int A::x = 0 ;
int main()
{
int size = 15;
A *tmp = new A[size]();
A *tmp1;
//I'm not sure here what is the currect symtax to do this:
for (int i = 0; i< size;i++)
{
tmp1[i] = new A(tmp[i]);
}
////////////////////////////////////////////////////
for (int i =0 ;i<size;i++)
{
//I want the same result in both prints
printf("tmp1:%d\n",i);
printf("age:%d m_int:%d static:%d\n",tmp1[i].getAge(),tmp1[i].getX(),tmp1[i].getStaticX());
printf("tmp:%d\n",i);
printf("age:%d m_int:%d static:%d\n",tmp[i].getAge(),tmp[i].getX(),tmp[i].getStaticX());
printf("EOF\n\n");
}
return 0;
}
thanks!