I am trying to figure out how the C++ key word "this" works. I followed the codes below, but it does not pass and show the error of
#include <iostream>
#include <string>
void PrintEntity(const Entity& e);
class Entity
{
public:
int x, y;
Entity(int x, int y)
{
this->x = x;
this->y = y;
PrintEntity(*this);
}
};
void PrintEntity(const Entity& e)
{
std::cout << "Entity" << std::endl;
}
int main()
{
return 0;
}
I reviewed other similar questions, the solutions include adding "return 0" to the Main function or circular dependency. But I don't think these solutions apply for me. Please help me solve it, thanks!
Aucun commentaire:
Enregistrer un commentaire