I'm new to C++ so I watch some Youtube Videos, I was watching a video about the arrow operator and also typing the code in the video
#include<iostream>
using namespace std;
class Entity{
public:
void display(){
cout<<"Inside Entity"<<endl;
}
};
class Smatrptr{
private:
Entity* e;
public:
Smatrptr(Entity* entity)
:e(entity)
{
}
~Smatrptr(){
delete e;
}
Entity* getEntity(){
return e;
}
};
int main(){
Smatrptr smrt = new Entity();
smrt.getEntity()->display();
return 0;
}
the code compile and run fine , what I don't understand is the line
Smatrptr smrt = new Entity();
as you can see smrt
is of Type Smatrptr
while new Entity
is of type Entity*
so how there is no "type mismatch" here?