Originally Posted by
Salem
-Stack => a local variable
-Heap => you call new or new[]
-static => you declare it outside of a function
I have that:
Code:
#include <iostream>
#include <string>
using namespace std;
class X
{
public:
X();
~X();
static void Y (void);
static string my_str;
};
X::X(void)
{
cout << "Call constructor" << endl;
}
X::~X(void)
{
cout << "Call destructor" << endl;
}
Y::init(void)
{
my_str = "Call static constructor";
}
int main( )
{
X x;
X *xarray = new X[5];
delete [] xarray;
Y::init();
return (0);
}
But this is not working. Where are my mistake(s)?