I ran the below program and it is running fine. but I don't understand even if the objectaa is not initialized anywhere in the code and it is just an object pointer, then how the dummyfn of class Aa is getting called?
#include<bits/stdc++.h>
using namespace std;
class Aa
{
public:
int a;
void dummyfn (string ss);
};
void Aa::dummyfn(string ss)
{
cout<<"calling fun from Aa "<<ss<<endl;
}
class bb
{
public:
int b;
Aa *objectaa;
void bbfun();
};
void bb::bbfun()
{
cout<<"calling the bb function"<<endl;
string str = "ffff";
objectaa->dummyfn(str);
}
int main()
{
bb *objectb = new bb();
objectb->bbfun();
return 0;
}