I have looked up all the previous posts I could find on SO on this error, but my case seems to be distinct. Here is the code under consideration (I have not reproduced the complete source here, but I am guessing what has been provided should suffice for the experts on this forum to figure out the cause):
//.h files
#ifndef KEY_BOARD_H
#define KEY_BOARD_H
...
class key_board_checker;
class key_board{
friend class key_board_checker;
...
private:
struct PrivateTag{};
public:
static const key_board& get_instance();
key_board(PrivateTag);
~key_board() = default;
...
protected:
static bool has_instance;
private:
key_board (const key_board&) = delete;
key_board& operator = (const key_board&) = delete;
private:
static unique_ptr<key_board> keyboardPtr;
...
};
...
#include "key_board_checker.h"
#endif
#ifndef KEY_BOARD_CHECKER_H
#define KEY_BOARD_CHECKER_H
...
class key_board;
class key_board_checker{
public:
key_board_checker(const key_board& rkb);
~key_board_checker()=default;
protected:
private:
key_board_checker(const key_board_checker&)=delete;
key_board_checker& operator=(const key_board_checker&)=delete;
...
private:
const key_board& rkb;
private:
static const unsigned short numalnumidx = 18;
...
private:
//housekeeping
vector<vector<string>>final;
private:
...
void check_keyboard () const;
void step1 () const;
...
};
#include "key_board.h"
#endif
//.cpp file
key_board_checker::key_board_checker(const key_board& rkb):rkb(rkb){
...
check_keyboard();
}
void key_board_checker::check_keyboard() const {
...
step1();
return;
}
void key_board_checker::step1()const {
...
final.resize(numalnumidx);
...
//main
#include "key_board.h"
#include "key_board_checker.h"
int main (){
auto const& kbr = key_board::get_instance();
key_board_checker kbc(kbr);
return 0;
}
I am perplexed by the following error thrown by the g++ compiler:
key_board_checker.cpp: In member function ‘void key_board_checker::step1() const’:
key_board_checker.cpp:56:27: error: passing ‘const std::vector<std::vector<std::__cxx11::basic_string<char> > >’ as ‘this’ argument discards qualifiers [-fpermissive]
final.resize(numalnumidx);
^
compilation terminated due to -Wfatal-errors.
What am I missing here?
TIA