Error C2662 Volatile
Contents |
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 this site About Us Learn more about Stack Overflow error c2662 conversion loses qualifiers the company Business Learn more about hiring developers or posting ads with us Stack Overflow
Error C2662 Cannot Convert 'this' Pointer From
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
C++ Error C2662
4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Defining volatile class object up vote 5 down vote favorite Can the volatile be used for class objects?
C2662 Cannot Convert This Pointer From Const
Like: volatile Myclass className; The problem is that it doesn't compile, everywhere when some method is invoked, the error says: error C2662: 'function' : cannot convert 'this' pointer from 'volatile MyClass' to 'MyCLass &' What is the problem here and how to solve it? EDIT: class Queue { private: struct Data *data; int amount; int size; public: Queue (); ~Queue (); bool volatile push(struct Data element); bool volatile pop(struct Data *element); void volatile cannot convert this pointer from const to & cleanUp(); }; ..... volatile Queue dataIn; ..... EnterCriticalSection(&CriticalSection); dataIn.push(element); LeaveCriticalSection(&CriticalSection); c++ volatile share|improve this question edited Jun 20 '10 at 5:19 asked Jun 20 '10 at 4:38 maximus 1,41753574 Note that in C++, volatile does not guarantee thread-safety. That's different from, for example, .NET, where it does. –sbi Jun 20 '10 at 7:49 add a comment| 4 Answers 4 active oldest votes up vote 9 down vote accepted Yes, you can, but then you can only call member functions that are declared volatile (just like the const keyword). For example: struct foo { void a() volatile; void b(); }; volatile foo f; f.a(); // ok f.b(); // not ok Edit based on your code: bool volatile push(struct Data element); declares a non-volatile member function that returns a bool volatile (= volatile bool). You want bool push(struct Data element) volatile; share|improve this answer edited Jun 20 '10 at 5:29 answered Jun 20 '10 at 4:40 Jesse Beder 18.3k1372117 1 What about constructors and destructors and variables(properties) declared in class? –maximus Jun 20 '10 at 4:44 I did as you said, but anyway the same error messages.. –maximus Jun 20 '10 at 4:49 1 @maximus, constructors and destructors can't be overloaded with volatile (or const), and member variables inherit these prop
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 this site About Us Learn more about Stack Overflow the company Business Learn more about hiring c++ const method developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask c++ const function 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 const_cast them; it only takes a minute: Sign up Problems with STL as a static volatile member up vote 0 down vote favorite I'm trying to compile something like this: #include class thread { public: static volatile std::list
コンパイラ先生は優秀で、NRVOという最適化をしてくれることがあります。この最適化を施してくれると次のようなコードにおいて、 #include
used for class objects? Like: volatile Myclass className; The problem is that it doesn't compile, everywhere when some method is invoked, the error says: error C2662: 'function' : cannot convert 'this' pointer from 'volatile MyClass' to 'MyCLass &' What is the problem here and how to solve it? EDIT: class Queue { private: struct Data *data; int amount; int size; public: Queue (); ~Queue (); bool volatile push(struct Data element); bool volatile pop(struct Data *element); void volatile cleanUp(); }; ..... volatile Queue dataIn; ..... EnterCriticalSection(&CriticalSection); dataIn.push(element); LeaveCriticalSection(&CriticalSection);
Game | 2010-06-20 I think he meant to say bool push(struct Data element) volatile; instead of bool volatile push(struct Data element); Also have a look here http://www.devx.com/tips/Tip/13671 SUPPORT US 筝恰絵緇篆≦篌 莚丞阪, 醇筝贋篏莚丞膣√ 息 2016 莚丞阪 kechengpuzi@gmail.com 莚丞阪筝膾283紊 莚丞阪鐚罸鎀篏菴罩ヤ ICP紊16011938-2