I am making a tradition list using templates in C++ and also obtain some compilation error.The code is extremely large in size , so below is a little snippet of the code from wbelow the error is coming. Compilation error is provided listed below. You deserve to compile it your very own device to watch the very same error.

#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() ’ int length() rerotate m_count;


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

By clicking “Message Your Answer”, you agree to our terms of service, privacy policy and also cookie plan


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


Your privacy

By clicking “Accept all cookies”, you agree Stack Exreadjust have the right to keep cookies on your device and also disclose indevelopment in accordance via our Cookie Policy.