#include <iostream>
using namespace std;
class First{
public:
void fun()
{
cout<<"base fun called\n";
}
};
class Second{
public:
static First x;
static First *y;
};
First Second::x;
First* Second::y;
int main()
{
Second::x.fun();
Second::y->fun();
return 0;
}
Line 1 and line 2 are declarations, and lines 3 and line 4 are definitions, as I understood from some other stackoverflow posts about static members.
Q1. Why should we define static objects like this? (Line 3 and line 4)
Q2. What is the difference between x and y? (Line 1 and line 2)
Q3. Where is the memory allocated for x and y objects? (Line 3 and line 4)
source
share