mercredi 1 novembre 2017

Functions out of scope error C++

My code has a class compROS. I have created 2 functions requestStart and requestNotStart which are trying to call is_started_ and sec_ from class compROS. Now whenever I run the code, I get the following errors - functions requestStart and requestNotStart and is_started_ and sec_ were not declared in this scope. My assumption is that the private functions are not accessible from the outside of the class. Should I add requestStart and requestNotStart as friend functions??

What is the most efficient way of tackling these errors?

Following is my code -

using namespace std;
namespace Lib
{
  class compROS
  {
    public:
      compROS(string error_text, int sec):
        error_text_(error_text),
        is_started_(false),
        sec_(sec)
        {
        }

    private:
      string error_text_;
      bool is_started_;
      int sec_;
  };
}

int requestStart()
{
  if(!is_started_)
    sec_ = 2;
    // Start timer
    // Timer expired
  is_started_ = true;
  return 0;
}

int requestNotStart()
{
  // <Code to be inserted>
  return 0;
}

int main (int argc, char **argv)
{

}

Aucun commentaire:

Enregistrer un commentaire