-1

These are some parts of my crawler header file. I cannot make changes to this header file.

private:
    int top_position;         // The maximum position of the throttle
    bool left_reverse;        // true if left direction is reverse
    bool right_reverse;       // true if right direction is reverse

So I tried to implement left_reverse in my implementation file. This is still a stub though.

bool left_reverse()
 {
   return(false);
 }

And I use it in implementing other function.

double Crawler::left_engine_speed() const
{
  double speedpercentage;
  double hundred(100.0);
  speedpercentage = left_throttle.flow()*hundred;
  if(left_reverse())     // <<< HERE IT IS 
    {
      speedpercentage=speedpercentage*(-1);
    }

  return(speedpercentage);
}

However I receive an error telling me error: '((const Vehicles::Crawler*)this)->Vehicles::Crawler::left_reverse' cannot be used as a function. Can someone tell me the problem here?

Luigi
  • 4,129
  • 6
  • 37
  • 57

2 Answers2

1

It's not a function. It's a variable. There is no useful way to pretend it's a function. At all. Period.

user253751
  • 57,427
  • 7
  • 48
  • 90
0

If the function is declared in some name space for example in the global name space then write

double Crawler::left_engine_speed() const
{
  double speedpercentage;
  double hundred(100.0);
  speedpercentage = left_throttle.flow()*hundred;
  if(::left_reverse())     // <<< HERE IT IS 
    {
      speedpercentage=speedpercentage*(-1);
    }

  return(speedpercentage);
}

or

if(SomeNameSpace::left_reverse()) 

Or

double Crawler::left_engine_speed() const
{
  bool left_reverse();
  double speedpercentage;
  double hundred(100.0);
  speedpercentage = left_throttle.flow()*hundred;
  if(left_reverse())     // <<< HERE IT IS 
    {
      speedpercentage=speedpercentage*(-1);
    }

  return(speedpercentage);
}

Here is a simple example

#include <iostream>

class Crawler
{
public:
    double left_engine_speed() const;
private:
    bool right_reverse; 
};

bool left_reverse() { return true; }

double Crawler::left_engine_speed() const
{
    if ( left_reverse() ) return 1.0;
    else return 0.0;
}

int main() 
{
    std::cout << Crawler().left_engine_speed() << std::endl;

    return 0;
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • Thanks for your help. But when I put the namespace in front of it, i receive an error saying it is not a member of the namespace. – user3312239 Feb 15 '14 at 01:22