Request for member ‘pixelWidth’ in ‘this’, which is of non-class type ‘Tile* const’

From Cppsyntax

Jump to: navigation, search

You can get the error

 request for member ‘bar’ in ‘this’, which is of non-class type ‘Foo* const’

if you use this in a member function of an object.

In Java, 'this' is an instance; in C++ it is a pointer to an instance.

WRONG

 class Foo
 {
   int getOne()
   {
     return 1;
   }
   int getTwo()
   {
     return this.getOne()+1;  // incorrect use of this
   }
 };

RIGHT

 class Foo
 {
   int getOne()
   {
     return 1;
   }
   int getTwo()
   {
     return this->getOne()+1;  // incorrect use of this
   }
 };

ALSO RIGHT

 class Foo
 {
   int getOne()
   {
     return 1;
   }
   int getTwo()
   {
     return getOne()+1;  // incorrect use of this
   }
 };

Further information

more on the 'this' pointer

Personal tools