#include <iostream>
#include <string>
using namespace std;
class Check
{
public:
int a{};
string b{};
float c{};
void print()
{
cout << "What!";
}
Check()
{
cout << "Constructor has called";
}
~Check()
{
cout << "Destructor has called ";
}
};
int main()
{
Check* ptr{};
ptr->print(); /*How and why is it working without any error or undefined behaviour even though i did not store an address of object in it */
return 0;
}
I am using Visual Studio 2019 updated version
According to my knowledge, we can access the members of the class through pointers by making pointer to the class and then store the address of an object of that class type, and then we can access the members through '->' using that pointer