In the main function in this code what does this (ScopedPtr ent = new Entity()) mean Why we are not using (ScopedPtr*) as per C++ instantiating style
#include<string>
class Entity
{
public:
Entity()
{
std::cout << "Created Entity!" << std::endl;
}
void Print()
{
std::cout << "Print" << std::endl;
}
};
class ScopedPtr
{
private:
Entity* m_Ptr;
public:
ScopedPtr( Entity* ptr)
: m_Ptr(ptr)
{}
/*ScopedPtr()
{
std::cout << "Hello";
}*/
~ScopedPtr()
{
std::cout << "Deleted Pointer";
delete m_Ptr;
}
};
int main()
{
{
ScopedPtr ent = new Entity();
And why the ScopedPtr(Entity Constructor) Didn't take a Entity* parameter and the code ran successfully
}
std::cin.get();
}
ScopedPtr( Entity* ptr). It does have anEntity*parameter - M.Mexplicit- WaqarScopedPtr ent = new Entity()in this code it didn't take a actual parameter in the main function. - Ishit Jaiswal