#incorporate utilizing namespace std;theme class sortedList int m_count; public: sortedList()m_count = 0; int length() rerevolve m_count; ; void output(const sortedList& list) cout list1; output(list1); return 0;I am obtaining compilation error :
prog.cpp: In function ‘void output(const sortedList&)’:prog.cpp:17:35: error: passing ‘const sortedList’ as ‘this’ dispute discards qualifiers <-fpermissive> cout ::length()
You are watching: Passing const as this argument discards qualifiers
You have to make size to be const-qualified:
int length() rerevolve m_count; →
int length() const rerotate m_count;
As already stated, one choice is to make size const-qualified.Another alternative is to usage const_cast within the output function.sortedList& ref = const_cast &>(list);cout (2) is especially advantageous once we do not have the deluxe to update the course strategy discussed in (1).
Thanks for contributing a solution to Stack Overflow!Please be sure to answer the question. Provide details and share your research!
But avoid …Asking for aid, clarification, or responding to various other answers.Making statements based on opinion; ago them up via referrals or individual suffer.
To learn even more, watch our tips on composing good answers.
Post Your Answer Discard
Getting passing ‘const std::map’ as ‘this’ debate discards qualifiers <-fpermissive> in lambda role
See more: Here'S Why Snapchat Killed The Barfing Rainbow Mouth On Snapchat Lens
site style / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2021.9.10.40187