How to access void functions from a class in main in C++

Only two functions are giving me trouble and they are of type void. I'm getting these errors:

prog.cpp: In function ‘int main()’:
prog.cpp:252:20: error: ‘void hillClimbing::placeQueens()’ is private within 
this context
hc.placeQueens();
                ^
 prog.cpp:19:10: note: declared private here
 void placeQueens( ){
      ^~~~~~~~~~~
prog.cpp:253:18: error: ‘void hillClimbing::moveQueen()’ is private within 
this context
 hc.moveQueen();
              ^
prog.cpp:36:11: note: declared private here
  void moveQueen( ){
       ^~~~~~~~~

Is there any possible way for me to access these functions? (Note: I have other functions as well but they don't relate to the issue). I am trying to create an instance of my class in main and none of the other functions are giving me trouble. Just the ones of type void. Any thoughts on how I can access these functions? This is how I am trying to create an instance of the hillClimbing class and calling the placeQueens and moveQueen functions.

1 answer

  • answered 2018-02-13 01:46 Lightness Races in Orbit

    You made the functions private.

    • If you do not want them to be private, make them not private.

    • If you do require them to be private, make the calling scope a friend.

    Those are your options.

    Remember that if you declared your class with the keyword class, members are private until protected: or public: is encountered (which you may have forgotten to write).

    If you declared your class with the keyword struct, members are public until protected: or public: is encountered.