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
andrequestNotStart
andis_started_
andsec_
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 -
(Updated my code based on the comments from @Snps and @Philip Brack)
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(Lib::compROS& c)
{
if(!c.is_started_)
sec_ = 2;
// Start timer
// Timer expired
c.is_started_ = true;
return 0;
}
int requestNotStart(Lib::compROS& c)
{
// <Code to be inserted>
return 0;
}
int main (int argc, char **argv)
{
Lib::compROS c("error", 2);
requestStart(c);
requestNotStart(c);
return 0;
}