cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
using new in constructor
using new in constructor
Nov 23, 2011 at 10:04pm UTC
acorn
(276)
I read on the net it was a bad idea to allocate new memory in the constructor or generally any initialization that can fail should be moved to its own function.
can someone explain this or offer some more information on this.
Nov 23, 2011 at 10:17pm UTC
Peter87
(11234)
If memory allocation with new fails it will throw an exception, nothing wrong with that. People are just stupid.
Nov 23, 2011 at 10:42pm UTC
Cubbi
(4774)
On the contrary, the constructor is the ideal place for memory allocation and other resource acquisition. See
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
Nov 23, 2011 at 10:48pm UTC
acorn
(276)
ok i guess its true you dont believe everything you read on the internet ehe. thanks guys.
Topic archived. No new replies allowed.