- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Consider the following code:
#include <iostream> class MyClass { const int value; public: explicit MyClass() : value(10) { } MyClass(int val) : value(val) { } int GetValue() { return value; } }; int main() { MyClass a, b(20); std::cout << "a.value = " << a.GetValue() << " b.value = " << b.GetValue() << std::endl; b = a; std::cout << "a.value = " << a.GetValue() << " b.value = " << b.GetValue() << std::endl; return 0; }
When built with Composer 2013 SP1 Update 4 on Windows, I get:
a.value = 10 b.value = 20
a.value = 10 b.value = 10
Two questions:
1. Why does this compile? Neither g++ nor MSVC will compile it because of the const member, which cannot be overwritten in the default assignment operator.
2. Why does assignment modify the const value?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi John,
Yes, it shouldn't compile and should output an error on copying not allowed for assignment operator for const member value. It worked fine on LInux with the latest icc version but on windows it didn't output the error. I'll file this issue with the developers and will update you accordingly as soon as I've an update. Appreciate your patience till then.
_Regards, Kittur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Kittur Ganesh (Intel) wrote:
[...] I'll file this issue with the developers and will update you accordingly as soon as I've an update. Appreciate your patience till then.
Please, could we have a tracking number?
PS: I encourage all @Intel members to always write tracking numbers for bugs/feature requests, so we can check them in the release notes of the new version. TIA!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure, the tracking number is: DPD200361059 BTW, I'll update this post as soon as the release with the fix is out as well. Appreciate your patience through this, as always.
_Kittur

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page