Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Roman Perepelitsa<Roman.Perepelitsa@gmail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Definition of const object |
| Date | 2011-12-06 13:52 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <14174863.133.1323173824046.JavaMail.geo-discussion-forums@vbaa2> (permalink) |
The standard mentions that modifying a const object results in
undefined behavior, but I couldn't find a definition of const object.
Can a heap-allocated object be a const object?
#include<iostream>
int main() {
const int* p = new const int(42);
// Modifying a const objects is undefined behavior.
// Does p point to a const object?
*const_cast<int*>(p) = 24;
// Is it required to print 24?
std::cout<< *p<< std::endl;
}
Roman Perepelitsa.
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Next in thread | Find similar
Definition of const object Roman Perepelitsa<Roman.Perepelitsa@gmail.com> - 2011-12-06 13:52 -0800 Re: Definition of const object Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-12-09 23:54 -0800
csiph-web