Base operand of arrow has non-pointer type ‘Foo’

From Cppsyntax

Jump to: navigation, search

You can get the error

 base operand of ‘->’ has non-pointer type ‘Foo’

if you try to use a "->" where you should be using a ".".

It is a little bit difficult to make this happen, since new Foo() returns a pointer to Foo, but you can get in this situation with references.

WRONG

 class Foo 
 {
   int i;
   public: int getI()
   {
     return i;
   }
 };
 class Blort
 {   
   int one(Foo &aFoo)
   {
     aFoo->getI();       // aFoo is a non-pointer type here
   }
 };

RIGHT

 class Foo 
 {
   int i;
   public: int getI()
   {
     return i;
   }
 };
 class Blort
 {   
   int one(Foo &aFoo)
   {
     aFoo.getI();       // use a "." instead of a "->"
   }
 };
pharmacie en ligne viagra professional cialis professional acheter viagra soft acheter viagra acheter propecia acheter cialis acheter tadalis acheter silagra acheter levitra acheter kamagra acheter caverta acheter kamagra oral jelly acheter cialis soft acheter kamagra soft
Personal tools