I can access member functions of a null shared_ptr object :
#include <memory>
#include <iostream>
class A
{
public:
int getNum() {return 1234;}
};
int main()
{
std::shared_ptr<A> pA(nullptr);
std::cout << pA->getNum() << std::endl;
}
returns 1234 while I was expecting an exception. Same result happens for
std::shared_ptr<A> pA();
or
std::shared_ptr<A> pA();
pA.reset();
Is this really the expected behaviour ? If it is what is the corect shared_ptr defination that throws an exception in case of a member function call ?
Using VS2010.