Home > error c2662 > error c2662 visual studio

Error C2662 Visual Studio

Contents

resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9

Error C2662 Conversion Loses Qualifiers

Documentation APIs and reference Dev centers Retired content Samples We’re sorry. error c2662 cannot convert 'this' pointer from The content you requested has been removed. You’ll be auto redirected in 1 second. C/C++ Building Reference C/C++ c++ error c2662 Build Errors Compiler Errors C2600 Through C2699 Compiler Errors C2600 Through C2699 Compiler Error C2662 Compiler Error C2662 Compiler Error C2662 Compiler Error C2600 Compiler Error C2601 Compiler Error

C2662 Cannot Convert This Pointer From Const

C2602 Compiler Error C2603 Compiler Error C2605 Compiler Error C2611 Compiler Error C2612 Compiler Error C2613 Compiler Error C2614 Compiler Error C2616 Compiler Error C2617 Compiler Error C2619 Compiler Error C2624 Compiler Error C2626 Compiler Error C2627 Compiler Error C2628 Compiler Error C2630 Compiler Error C2632 Compiler Error C2633 Compiler Error C2634 Compiler Error C2635 Compiler Error C2636

Cannot Convert This Pointer From Const To &

Compiler Error C2637 Compiler Error C2638 Compiler Error C2640 Compiler Error C2645 Compiler Error C2646 Compiler Error C2647 Compiler Error C2648 Compiler Error C2649 Compiler Error C2650 Compiler Error C2651 Compiler Error C2652 Compiler Error C2653 Compiler Error C2654 Compiler Error C2655 Compiler Error C2656 Compiler Error C2657 Compiler Error C2658 Compiler Error C2659 Compiler Error C2660 Compiler Error C2661 Compiler Error C2662 Compiler Error C2663 Compiler Error C2664 Compiler Error C2665 Compiler Error C2666 Compiler Error C2667 Compiler Error C2668 Compiler Error C2669 Compiler Error C2670 Compiler Error C2671 Compiler Error C2673 Compiler Error C2674 Compiler Error C2675 Compiler Error C2676 Compiler Error C2677 Compiler Error C2678 Compiler Error C2679 Compiler Error C2680 Compiler Error C2681 Compiler Error C2682 Compiler Error C2683 Compiler Error C2687 Compiler Error C2688 Compiler Error C2689 Compiler Error C2690 Compiler Error C2691 Compiler Error C2692 Compiler Error C2693 Compiler Error C2694 Compiler Error C2695 Compiler Error C2696 Compiler Error C2698 TOC Collapse the table of content Expand the table of content This documentation is archived

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of c++ const method this site About Us Learn more about Stack Overflow the company Business

C++ Const Function

Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask const_cast Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign https://msdn.microsoft.com/en-us/library/2s2d2tez.aspx up Why isn't this compiling? up vote 1 down vote favorite I don't understand why the below code does not build: bool AguiRectangle::pointInside(const AguiPoint &p ) { if(p.getX() < x) return false; if(p.getY() < y) return false; if(p.getX() >= x + width) return false; if(p.getY() >= y + height) return false; return true; } I get this: Error 1 error C2662: 'AguiPoint::getX' : http://stackoverflow.com/questions/3898663/why-isnt-this-compiling cannot convert 'this' pointer from 'const AguiPoint' to 'AguiPoint &' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\aguibasetypes.cpp 259 Error 3 error C2662: 'AguiPoint::getX' : cannot convert 'this' pointer from 'const AguiPoint' to 'AguiPoint &' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\aguibasetypes.cpp 261 Error 2 error C2662: 'AguiPoint::getY' : cannot convert 'this' pointer from 'const AguiPoint' to 'AguiPoint &' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\aguibasetypes.cpp 260 Error 4 error C2662: 'AguiPoint::getY' : cannot convert 'this' pointer from 'const AguiPoint' to 'AguiPoint &' c:\users\josh\documents\visual studio 2008\projects\agui\alleg_5\agui\aguibasetypes.cpp 262 c++ share|improve this question asked Oct 10 '10 at 1:48 jmasterx 15.7k48195403 add a comment| 1 Answer 1 active oldest votes up vote 15 down vote accepted The functions AguiPoint::getX() and AguiPoint::getY() need to be defined as const member functions or you won't be able to call them on const AguiPoints. You attempted to call a non-const member function on p, which is reference to a const AguiPoint. Since references are aliases to the original object, calling a non-const member function on a const AguiPoint & is equivalent to calling a non-const member function on a const AguiPoint, which is an error. It's an error because since the method was not declared

here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the http://stackoverflow.com/questions/8415688/visual-studio-error-c2662-calling-const-methods workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs https://bytes.com/topic/c/answers/628845-error-c2662-cannot-convert-pointer Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join error c2662 them; it only takes a minute: Sign up Visual Studio: error C2662 - calling const methods up vote 0 down vote favorite EDIT: Silly mistake. Somehow I was using source code files from another folder, for another project, to compile. Was opening the files from Windows explorer and seeing all the consts as they should be, then realised that opening c2662 cannot convert the "same files" from within the Solution Explorer showed different contents. Further checking showed the files associated with the project I was trying to build were not the files I was currently editing. Lesson learned - be more careful with version control. Thanks for the comments, they helped me look down the right lines and stop banging my head off the keyboard looking for a typo. ======================================================== I'm getting multiple "error C2662"s errors in the following code (positions shown in comments): XYVector Rocket::avoidRocketsAndPlanets(float distance, const std::set& otherRockets, const std::set& planets) const { XYVector c = XYVector(); for (std::set::const_iterator it = otherRockets.begin(); it != otherRockets.end(); it++) { if ((it->getPos() - pos).mod() < distance) { c -= (it->getPos() - pos); } } for (std::set::const_iterator it = planets.begin(); it != planets.end(); it++) { XYVector planetPos = it->getPos(); // ^ error C2662: 'Planet::getPos' : cannot convert 'this' pointer from 'const Planet' to 'Planet &' if ((planetPos - pos).mod() < (distance + it->getRadius())) // ^ error C2662: 'Planet::getRadius' : cannot convert 'this' pointer from 'const Planet' to 'Planet &' { c

your question and get tips & solutions from a community of 418,505 IT Pros & Developers. It's quick & easy. error C2662 cannot convert this pointer.. P: 9 mishink7 i am getting this error error C2662: 'std::vector<_Ty>::push_back' : cannot convert 'this' pointer from 'const std::vector<_Ty>' to 'std::vector<_Ty> &' with [ _Ty=std::string ] and [ _Ty=std::string ] and [ _Ty=std::string ] this is my code inside the class customer void customer::add_movie(string move) const { int flag1=0; for (unsigned int i=0; i movies. ive tried doing different things, but i cant fix it, can anyone help please? Apr 6 '07 #1 Post Reply Share this Question 3 Replies P: 9 mishink7 bumpssssssssssss Apr 6 '07 #2 reply Expert Mod 5K+ P: 8,916 Banfa bumpssssssssssss Only waiting an hour before bumping is really not waiting long enough. The forum experts are not all in the same time zone as you. You should leave a post at least 24 hours before bumping. Apr 6 '07 #3 reply Expert Mod 5K+ P: 8,916 Banfa error C2662: 'std::vector<_Ty>::push_back' : cannot convert 'this' pointer from 'const std::vector<_Ty>' to 'std::vector<_Ty> &' with [ _Ty=std::string ] and [ _Ty=std::string ] and [ _Ty=std::string ] Read the error, the is a type mismatch between 'const std::vector<_Ty>' to 'std::vector<_Ty> &' where_ty=std:string (or string). Substituting there is a type mismatch between 'const std::vector' to 'std::vector &', you can not convert between a const object an a non-const reference to an object. Now look at your function Expand|Select|Wrap|Line Numbers voidcustomer::add_movie(stringmove)const { intflag1=0; for(unsignedinti=0;i movies. See any const qualifiers? Yes on the func

 

Related content

c2662 error

C Error table id toc tbody tr td div id toctitle Contents div ul li a href Error C a li li a href Error C a li li a href Error C a li li a href Error C Conversion Loses Qualifiers a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of relatedl this site About Us Learn more about Stack Overflow the p h id Error C p company Business Learn more about hiring developers

error 1 error c2662

Error Error C table id toc tbody tr td div id toctitle Contents div ul li a href Error C Cannot Convert This Pointer From Const To Conversion Loses Qualifiers a li li a href Const Method a li ul td tr tbody table p resources Windows Server resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community relatedl Magazine Forums Blogs Channel Documentation APIs and reference error c conversion loses qualifiers Dev centers Retired content Samples We re sorry The content you requested has error c cannot convert this pointer from

error c2662 msdn

Error C Msdn table id toc tbody tr td div id toctitle Contents div ul li a href Error C Conversion Loses Qualifiers a li li a href C a li li a href C Const Function a li ul td tr tbody table p XXX to XXX Visual Studio Languages Windows Desktop Development C Standards Extensions and Interop Question relatedl Sign in to vote Please look at my p h id Error C Conversion Loses Qualifiers p code pragma once class CBox protected double m length double m width double m high error c cannot convert this pointer from

error c2662 volatile

Error C Volatile table id toc tbody tr td div id toctitle Contents div ul li a href Error C Cannot Convert this Pointer From a li li a href C Error C a li li a href C Cannot Convert This Pointer From Const a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies relatedl of this site About Us Learn more about Stack Overflow error c conversion loses qualifiers the company Business Learn more about hiring

error c2662 cannot convert this

Error C Cannot Convert This table id toc tbody tr td div id toctitle Contents div ul li a href Error C Conversion Loses Qualifiers a li li a href Error C Cannot Convert This Pointer From Const To Conversion Loses Qualifiers a li li a href Const Function a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss relatedl the workings and policies of this site About Us Learn error c cannot convert this pointer from const to more about Stack

error c2662

Error C table id toc tbody tr td div id toctitle Contents div ul li a href Error C a li li a href Error C a li li a href Error C a li ul td tr tbody table p resources Windows Server resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups relatedl TechRewards Events Community Magazine Forums Blogs Channel Documentation error c conversion loses qualifiers APIs and reference Dev centers Retired content Samples We re sorry The error c cannot convert this pointer from content you requested has been removed You ll

error c2662 this const

Error C This Const table id toc tbody tr td div id toctitle Contents div ul li a href Error C Conversion Loses Qualifiers a li li a href Const Method a li li a href Const cast Example a li li a href Const Function a li ul td tr tbody table p resources Windows Server resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards relatedl Events Community Magazine Forums Blogs Channel Documentation APIs c error c cannot convert this pointer from const to and reference Dev centers Retired content Samples We

error c2662 cannot

Error C Cannot table id toc tbody tr td div id toctitle Contents div ul li a href Error C Cannot Convert this Pointer From a li li a href Cannot Convert This Pointer From Const To a li li a href Const cast Example a li li a href Const Correctness a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies relatedl of this site About Us Learn more about Stack Overflow the p h id Error

error c2662 iterator

Error C Iterator p here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss relatedl the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of million programmers just like you helping each other Join them it only takes a minute Sign up Visual Studio error C - calling const methods

error c2662 copy constructor

Error C Copy Constructor table id toc tbody tr td div id toctitle Contents div ul li a href Error C Cannot Convert this Pointer From a li ul td tr tbody table p Programming Boards C Programming Copy constructor error 'this' pointer conversion Getting started with C or C C relatedl Tutorial C Tutorial C and C FAQ error c conversion loses qualifiers Get a compiler Fixes for common problems Thread Copy constructor error 'this' p h id Error C Cannot Convert this Pointer From p pointer conversion Thread Tools Show Printable Version Email this Page hellip Subscribe to

error c2662 const

Error C Const table id toc tbody tr td div id toctitle Contents div ul li a href Cannot Convert This Pointer From Const To a li li a href Const cast Example a li li a href Const Function a li ul td tr tbody table p here for a quick overview of the site relatedl Help Center Detailed answers to any questions you c c might have Meta Discuss the workings and policies of this site error c conversion loses qualifiers About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or error

error c2662 cannot convert

Error C Cannot Convert table id toc tbody tr td div id toctitle Contents div ul li a href Visual Studio Error C a li li a href C Error C a li li a href Const Method a li ul td tr tbody table p here for a quick overview of the site Help Center Detailed answers relatedl to any questions you might have Meta Discuss the error c cannot convert this pointer from workings and policies of this site About Us Learn more about p h id Visual Studio Error C p Stack Overflow the company Business Learn