#include <iostream>
using namespace std;
class First{
public:
void fun()
{
cout<<"base fun called\n";
}
};
class Second{
public:
static First x; //Line 1
static First *y; //Line 2
};
First Second::x; //Line 3
First* Second::y; //Line 4
int main()
{
Second::x.fun();
Second::y->fun();
return 0;
}
Line 1 and Line 2 are declarations and Line 3 and Line 4 are definitions, this I have understood from some other stackoverflow posts about static members.
Q1. Why we have to define static objects like this ? (Line 3 and line 4)
Q2. Whats 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)